home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / term / extras / source / term-source.lha / termInit.c < prev    next >
C/C++ Source or Header  |  1995-07-01  |  111KB  |  5,170 lines

  1. /*
  2. **    termInit.c
  3. **
  4. **    Program initialization and shutdown routines
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* This variable helps us to remember whether the fast!
  13.      * macro panel was open or not.
  14.      */
  15.  
  16. STATIC BYTE HadFastMacros = FALSE;
  17.  
  18.     /* Remember whether we did pen allocation or not. */
  19.  
  20. STATIC BYTE AllocatedPens = FALSE;
  21.  
  22.     /* SafeOpenLibrary(STRPTR Name,LONG Version):
  23.      *
  24.      *    Try to open a library, but if there already is
  25.      *    a version in memory that's older than the release
  26.      *    we want flush it out first.
  27.      */
  28.  
  29. struct Library * __regargs
  30. SafeOpenLibrary(STRPTR Name,LONG Version)
  31. {
  32.     struct Library *Base;
  33.  
  34.     Forbid();
  35.  
  36.         /* Is this library already in memory? */
  37.  
  38.     if(Base = (struct Library *)FindName(&SysBase -> LibList,FilePart(Name)))
  39.     {
  40.             /* An old release? */
  41.  
  42.         if(Base -> lib_Version < Version)
  43.         {
  44.                 /* Flush it out. */
  45.  
  46.             RemLibrary(Base);
  47.         }
  48.     }
  49.  
  50.     Permit();
  51.  
  52.         /* Now reopen the library. */
  53.  
  54.     return(OpenLibrary(Name,Version));
  55. }
  56.  
  57.     /* TTYResize():
  58.      *
  59.      *    Signal AmigaUW that the window size has changed.
  60.      */
  61.  
  62. VOID
  63. TTYResize()
  64. {
  65.     if(Window)
  66.     {
  67.         BOOL    GotIt = TRUE;
  68.         LONG    Lines,Columns;
  69.  
  70.         if(XEmulatorBase && XEM_IO)
  71.         {
  72.             if(XEmulatorBase -> lib_Version >= 4)
  73.             {
  74.                 ULONG Result = XEmulatorInfo(XEM_IO,XEMI_CONSOLE_DIMENSIONS);
  75.  
  76.                 Columns    = XEMI_EXTRACT_COLUMNS(Result);
  77.                 Lines    = XEMI_EXTRACT_LINES(Result);
  78.             }
  79.             else
  80.                 GotIt = FALSE;
  81.         }
  82.         else
  83.         {
  84.             Columns    = LastColumn + 1;
  85.             Lines    = LastLine + 1;
  86.         }
  87.  
  88.         if(GotIt && WriteRequest)
  89.         {
  90.             WriteRequest -> IOSer . io_Command    = UWCMD_TTYRESIZE;
  91.             WriteRequest -> IOSer . io_Data        = (APTR)((Columns << 16) | (Lines));
  92.             WriteRequest -> IOSer . io_Length    = (WindowWidth << 16) | (WindowHeight);
  93.  
  94.             DoIO(WriteRequest);
  95.         }
  96.     }
  97. }
  98.  
  99.     /* LoadKeyMap(STRPTR Name):
  100.      *
  101.      *    Load a keymap file from disk.
  102.      */
  103.  
  104. STATIC struct KeyMap * __regargs
  105. LoadKeyMap(STRPTR Name)
  106. {
  107.     struct KeyMapResource    *KeyMapResource;
  108.     struct KeyMap        *Map = NULL;
  109.  
  110.         /* Try to get access to the list of currently loaded
  111.          * keymap files.
  112.          */
  113.  
  114.     if(KeyMapResource = (struct KeyMapResource *)OpenResource("keymap.resource"))
  115.     {
  116.         struct KeyMapNode *Node;
  117.  
  118.             /* Try to find the keymap in the list. */
  119.  
  120.         Forbid();
  121.  
  122.         if(Node = (struct KeyMapNode *)FindName(&KeyMapResource -> kr_List,FilePart(Config -> TerminalConfig -> KeyMapFileName)))
  123.             Map = &Node -> kn_KeyMap;
  124.  
  125.         Permit();
  126.     }
  127.  
  128.         /* Still no keymap available? */
  129.  
  130.     if(!Map)
  131.     {
  132.         APTR OldPtr = ThisProcess -> pr_WindowPtr;
  133.  
  134.             /* Disable DOS requesters. */
  135.  
  136.         ThisProcess -> pr_WindowPtr = (APTR)-1;
  137.  
  138.             /* Unload the old keymap code. */
  139.  
  140.         if(KeySegment)
  141.             UnLoadSeg(KeySegment);
  142.  
  143.             /* Try to load the keymap from the
  144.              * name the user entered.
  145.              */
  146.  
  147.         if(!(KeySegment = LoadSeg(Config -> TerminalConfig -> KeyMapFileName)))
  148.         {
  149.                 /* Second try: load it from
  150.                   * the standard keymaps drawer.
  151.                   */
  152.  
  153.             strcpy(SharedBuffer,"KEYMAPS:");
  154.  
  155.             if(AddPart(SharedBuffer,FilePart(Config -> TerminalConfig -> KeyMapFileName),MAX_FILENAME_LENGTH))
  156.             {
  157.                 if(!(KeySegment = LoadSeg(SharedBuffer)))
  158.                 {
  159.                     strcpy(SharedBuffer,"Devs:Keymaps");
  160.  
  161.                     if(AddPart(SharedBuffer,FilePart(Config -> TerminalConfig -> KeyMapFileName),MAX_FILENAME_LENGTH))
  162.                         KeySegment = LoadSeg(SharedBuffer);
  163.                 }
  164.             }
  165.         }
  166.  
  167.             /* Did we get the keymap file? */
  168.  
  169.         if(KeySegment)
  170.         {
  171.             struct KeyMapNode *Node = (struct KeyMapNode *)&((ULONG *)BADDR(KeySegment))[1];
  172.  
  173.             Map = &Node -> kn_KeyMap;
  174.         }
  175.  
  176.             /* Enable DOS requesters again. */
  177.  
  178.         ThisProcess -> pr_WindowPtr = OldPtr;
  179.     }
  180.     else
  181.     {
  182.         if(KeySegment)
  183.         {
  184.             UnLoadSeg(KeySegment);
  185.  
  186.             KeySegment = NULL;
  187.         }
  188.     }
  189.  
  190.     return(Map);
  191. }
  192.  
  193.     /* DeleteOffsetTables(VOID):
  194.      *
  195.      *    Delete the line multiplication tables.
  196.      */
  197.  
  198. STATIC VOID
  199. DeleteOffsetTables(VOID)
  200. {
  201.     if(OffsetXTable)
  202.     {
  203.         FreeVecPooled(OffsetXTable);
  204.  
  205.         OffsetXTable = NULL;
  206.     }
  207.  
  208.     if(OffsetYTable)
  209.     {
  210.         FreeVecPooled(OffsetYTable);
  211.  
  212.         OffsetYTable = NULL;
  213.     }
  214. }
  215.  
  216.     /* CreateOffsetTables(VOID):
  217.      *
  218.      *    Allocate the line multiplication tables.
  219.      */
  220.  
  221. STATIC BYTE
  222. CreateOffsetTables(VOID)
  223. {
  224.     LONG    Width    = (Window -> WScreen -> Width  + TextFontWidth)  * 2 / TextFontWidth,
  225.         Height    = (Window -> WScreen -> Height + TextFontHeight) * 2 / TextFontHeight;
  226.  
  227.     DeleteOffsetTables();
  228.  
  229.     if(OffsetXTable = (LONG *)AllocVecPooled(Width * sizeof(LONG),MEMF_ANY))
  230.     {
  231.         if(OffsetYTable = (LONG *)AllocVecPooled(Height * sizeof(LONG),MEMF_ANY))
  232.         {
  233.             LONG i,j;
  234.  
  235.             for(i = j = 0 ; i < Width ; i++, j += TextFontWidth)
  236.                 OffsetXTable[i] = j;
  237.  
  238.             for(i = j = 0 ; i < Height ; i++, j += TextFontHeight)
  239.                 OffsetYTable[i] = j;
  240.  
  241.             return(TRUE);
  242.         }
  243.     }
  244.  
  245.     DeleteOffsetTables();
  246.  
  247.     return(FALSE);
  248. }
  249.  
  250.     /* CopyItemFlags(struct MenuItem *Src,struct MenuItem *Dst):
  251.      *
  252.      *    Copy single menu item flags from one menu strip
  253.      *    to another.
  254.      */
  255.  
  256. STATIC VOID __regargs
  257. CopyItemFlags(struct MenuItem *Src,struct MenuItem *Dst)
  258. {
  259.     while(Src && Dst)
  260.     {
  261.         if(Src -> SubItem)
  262.             CopyItemFlags(Src -> SubItem,Dst -> SubItem);
  263.  
  264.         Dst -> Flags = Src -> Flags;
  265.  
  266.         Src = Src -> NextItem;
  267.         Dst = Dst -> NextItem;
  268.     }
  269. }
  270.  
  271.     /* CopyMenuFlags(struct Menu *Src,struct Menu *Dst):
  272.      *
  273.      *    Copy menu flags from one menu strip to
  274.      *    another.
  275.      */
  276.  
  277. STATIC VOID __regargs
  278. CopyMenuFlags(struct Menu *Src,struct Menu *Dst)
  279. {
  280.     struct MenuItem *SrcItem,*DstItem;
  281.  
  282.     while(Src && Dst)
  283.     {
  284.         SrcItem = Src -> FirstItem;
  285.         DstItem = Dst -> FirstItem;
  286.  
  287.         while(SrcItem && DstItem)
  288.         {
  289.             CopyItemFlags(SrcItem,DstItem);
  290.  
  291.             SrcItem = SrcItem -> NextItem;
  292.             DstItem = DstItem -> NextItem;
  293.         }
  294.  
  295.         Src = Src -> NextMenu;
  296.         Dst = Dst -> NextMenu;
  297.     }
  298. }
  299.  
  300.     /* UpdateTerminalLimits():
  301.      *
  302.      *    Check the current window size and extract the
  303.      *    size and position of the usable window rectangle.
  304.      */
  305.  
  306. VOID
  307. UpdateTerminalLimits()
  308. {
  309.     WindowLeft    = Window -> BorderLeft;
  310.     WindowTop    = Window -> BorderTop;
  311.  
  312.     WindowWidth    = Window -> Width - (Window -> BorderLeft + Window -> BorderRight);
  313.     WindowHeight    = Window -> Height - (Window -> BorderTop + Window -> BorderBottom);
  314.  
  315.     if(StatusWindow)
  316.     {
  317.         StatusDisplayLeft    = StatusWindow -> BorderLeft;
  318.         StatusDisplayTop    = StatusWindow -> BorderTop;
  319.         StatusDisplayWidth    = StatusWindow -> Width - (StatusWindow -> BorderLeft + StatusWindow -> BorderRight);
  320.         StatusDisplayHeight    = StatusWindow -> Height - (StatusWindow -> BorderTop + StatusWindow -> BorderBottom);
  321.     }
  322.     else
  323.     {
  324.         if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && !(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0]))
  325.         {
  326.             StatusDisplayLeft    = WindowLeft;
  327.             StatusDisplayTop    = Window -> Height - (Window -> BorderBottom + StatusDisplayHeight);
  328.             StatusDisplayWidth    = WindowWidth;
  329.  
  330.             WindowHeight -= StatusDisplayHeight;
  331.         }
  332.     }
  333.  
  334.     if(ChatMode && !(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0]))
  335.     {
  336.         if(CreateChatGadget())
  337.         {
  338.             UpdateChatGadget();
  339.  
  340.             WindowHeight -= (UserFontHeight + 2);
  341.  
  342.             ActivateChat(FALSE);
  343.         }
  344.     }
  345. }
  346.  
  347.     /* BuildMenu():
  348.      *
  349.      *    Create the menu strip, including quick dial menu.
  350.      */
  351.  
  352. STRPTR
  353. BuildMenu()
  354. {
  355.     struct NewMenu    *NewMenu;
  356.     struct Menu    *MenuNew;
  357.     LONG         PhoneCount = 0,
  358.              Count = 0,
  359.              i;
  360.  
  361.     BlockWindows();
  362.  
  363.         /* Clear the window menu strips. */
  364.  
  365.     if(Window)
  366.         ClearMenuStrip(Window);
  367.  
  368.     if(StatusWindow)
  369.         ClearMenuStrip(StatusWindow);
  370.  
  371.     if(FastWindow)
  372.         ClearMenuStrip(FastWindow);
  373.  
  374.         /* Count the number of menu entries in
  375.          * the base menu.
  376.          */
  377.  
  378.     while(TermMenu[Count++] . nm_Type != NM_END);
  379.  
  380.         /* Add the quick dial entries. */
  381.  
  382.     if(Phonebook)
  383.     {
  384.         for(i = 0 ; PhoneCount < DIAL_MENU_MAX && i < NumPhoneEntries ; i++)
  385.         {
  386.             if(Phonebook[i] -> Header -> QuickMenu)
  387.                 PhoneCount++;
  388.         }
  389.     }
  390.  
  391.         /* Allocate new menu prototypes. */
  392.  
  393.     if(NewMenu = (struct NewMenu *)AllocVecPooled((Count + PhoneCount) * sizeof(struct NewMenu),MEMF_ANY | MEMF_CLEAR))
  394.     {
  395.         CopyMem(TermMenu,NewMenu,Count * sizeof(struct NewMenu));
  396.  
  397.         if(PhoneCount)
  398.         {
  399.             Count--;
  400.  
  401.             PhoneCount = 0;
  402.  
  403.             FirstDialMenu = -1;
  404.  
  405.             for(i = 0 ; PhoneCount < DIAL_MENU_MAX && i < NumPhoneEntries ; i++)
  406.             {
  407.                 if(Phonebook[i] -> Header -> QuickMenu)
  408.                 {
  409.                     NewMenu[Count] . nm_Type    = NM_ITEM;
  410.                     NewMenu[Count] . nm_Label    = Phonebook[i] -> Header -> Name;
  411.                     NewMenu[Count] . nm_Flags    = CHECKIT;
  412.                     NewMenu[Count] . nm_UserData    = (APTR)(DIAL_MENU_LIMIT + i);
  413.  
  414.                     PhoneCount++;
  415.                     Count++;
  416.  
  417.                     if(FirstDialMenu == -1)
  418.                         FirstDialMenu = DIAL_MENU_LIMIT + i;
  419.                 }
  420.             }
  421.  
  422.             NewMenu[Count] . nm_Type = NM_END;
  423.         }
  424.         else
  425.             NewMenu[Count - 2] . nm_Type = NM_END;
  426. #if 0
  427.             /* Create the menu strip. */
  428.  
  429.         if(!(MenuNew = CreateMenus(NewMenu,TAG_DONE)))
  430.         {
  431.             FreeVecPooled(NewMenu);
  432.  
  433.             goto Simple;
  434.         }
  435.  
  436.             /* Do the menu layout. */
  437.  
  438.         if(!LayoutMenus(MenuNew,VisualInfo,
  439.             GTMN_NewLookMenus,    TRUE,
  440.             GTMN_TextAttr,        &UserFont,
  441.  
  442.             AmigaGlyph ? GTMN_AmigaKey :  TAG_IGNORE, AmigaGlyph,
  443.             CheckGlyph ? GTMN_Checkmark : TAG_IGNORE, CheckGlyph,
  444.         TAG_DONE))
  445.         {
  446.             FreeVecPooled(NewMenu);
  447.  
  448.             FreeMenus(MenuNew);
  449.  
  450.             goto Simple;
  451.         }
  452. #else
  453.         if(!(MenuNew = LT_NewMenuTemplate(Window -> WScreen,NULL,AmigaGlyph,CheckGlyph,NULL,NewMenu)))
  454.         {
  455.             FreeVecPooled(NewMenu);
  456.  
  457.             goto Simple;
  458.         }
  459. #endif
  460.         FreeVecPooled(NewMenu);
  461.     }
  462.     else
  463.     {
  464.             /* Create the menu strip. */
  465.  
  466. Simple:
  467. #if 0
  468.         if(!(MenuNew = CreateMenus(TermMenu,TAG_DONE)))
  469.         {
  470.             ReleaseWindows();
  471.  
  472.             return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_MENUS_TXT));
  473.         }
  474.  
  475.             /* Do the menu layout. */
  476.  
  477.         if(!LayoutMenus(MenuNew,VisualInfo,
  478.             AmigaGlyph ? GTMN_AmigaKey :  TAG_IGNORE, AmigaGlyph,
  479.             CheckGlyph ? GTMN_Checkmark : TAG_IGNORE, CheckGlyph,
  480.  
  481.             GTMN_NewLookMenus,    TRUE,
  482.             GTMN_TextAttr,        &UserFont,
  483.         TAG_DONE))
  484.         {
  485.             ReleaseWindows();
  486.  
  487.             FreeMenus(MenuNew);
  488.  
  489.             return(LocaleString(MSG_TERMINIT_FAILED_TO_LAYOUT_MENUS_TXT));
  490.         }
  491. #else
  492.         if(!(MenuNew = LT_NewMenuTemplate(Window -> WScreen,NULL,AmigaGlyph,CheckGlyph,NULL,TermMenu)))
  493.         {
  494.             ReleaseWindows();
  495.  
  496.             return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_MENUS_TXT));
  497.         }
  498. #endif
  499.     }
  500.  
  501.     if(Menu)
  502.     {
  503.         CopyMenuFlags(Menu,MenuNew);
  504. #if 0
  505.         FreeMenus(Menu);
  506. #else
  507.         LT_DisposeMenu(Menu);
  508. #endif
  509.     }
  510.  
  511.     Menu = MenuNew;
  512.  
  513.     if(Window)
  514.         SetMenuStrip(Window,Menu);
  515.  
  516.     if(StatusWindow)
  517.         SetMenuStrip(StatusWindow,Menu);
  518.  
  519.     if(FastWindow)
  520.         SetMenuStrip(FastWindow,Menu);
  521.  
  522.     ReleaseWindows();
  523.  
  524.     return(NULL);
  525. }
  526.  
  527.     /* Current2DefaultPalette(struct Configuration *SomeConfig):
  528.      *
  529.      *    Copy the current colour palette into the
  530.      *    default tables.
  531.      */
  532.  
  533. VOID __regargs
  534. Current2DefaultPalette(struct Configuration *SomeConfig)
  535. {
  536.     ColourTable    *Table = NULL;
  537.     UWORD        *Colour12;
  538.  
  539.     if(!SomeConfig)
  540.         SomeConfig = Config;
  541.  
  542.     switch(SomeConfig -> ScreenConfig -> ColourMode)
  543.     {
  544.         case COLOUR_EIGHT:
  545.  
  546.             if(Kick30)
  547.             {
  548.                 if(!ANSIColourTable)
  549.                     ANSIColourTable = CreateColourTable(8,ANSIColours,NULL);
  550.  
  551.                 Table = ANSIColourTable;
  552.             }
  553.  
  554.             Colour12 = ANSIColours;
  555.  
  556.             break;
  557.  
  558.         case COLOUR_SIXTEEN:
  559.  
  560.             if(Kick30)
  561.             {
  562.                 if(!EGAColourTable)
  563.                     EGAColourTable = CreateColourTable(16,EGAColours,NULL);
  564.  
  565.                 Table = EGAColourTable;
  566.             }
  567.  
  568.             Colour12 = EGAColours;
  569.  
  570.             break;
  571.  
  572.         case COLOUR_AMIGA:
  573.  
  574.             if(Kick30)
  575.             {
  576.                 if(!DefaultColourTable)
  577.                     DefaultColourTable = CreateColourTable(16,DefaultColours,NULL);
  578.  
  579.                 Table = DefaultColourTable;
  580.             }
  581.  
  582.             Colour12 = DefaultColours;
  583.  
  584.             break;
  585.  
  586.         case COLOUR_MONO:
  587.  
  588.             if(Kick30)
  589.             {
  590.                 if(!MonoColourTable)
  591.                     MonoColourTable = CreateColourTable(2,AtomicColours,NULL);
  592.  
  593.                 Table = MonoColourTable;
  594.             }
  595.  
  596.             Colour12 = AtomicColours;
  597.             break;
  598.     }
  599.  
  600.     if(Table)
  601.     {
  602.         if(SomeConfig -> ScreenConfig -> UseColours96)
  603.             Colour96xColourTable(SomeConfig -> ScreenConfig -> Colours96,Table,Table -> NumColours);
  604.         else
  605.         {
  606.             Colour12xColourTable(SomeConfig -> ScreenConfig -> Colours,Table,Table -> NumColours);
  607.  
  608.             Colour12x96(SomeConfig -> ScreenConfig -> Colours,SomeConfig -> ScreenConfig -> Colours96,16);
  609.  
  610.             SomeConfig -> ScreenConfig -> UseColours96 = TRUE;
  611.         }
  612.     }
  613.  
  614.     CopyMem(SomeConfig -> ScreenConfig -> Colours,Colour12,16 * sizeof(UWORD));
  615. }
  616.  
  617.     /* Default2CurrentPalette(struct Configuration *SomeConfig):
  618.      *
  619.      *    Copy the default palette to the current palette.
  620.      */
  621.  
  622. VOID __regargs
  623. Default2CurrentPalette(struct Configuration *SomeConfig)
  624. {
  625.     ColourTable    *Table = NULL;
  626.     UWORD        *Colour12;
  627.  
  628.     if(!SomeConfig)
  629.         SomeConfig = Config;
  630.  
  631.     switch(SomeConfig -> ScreenConfig -> ColourMode)
  632.     {
  633.         case COLOUR_EIGHT:
  634.  
  635.             Table        = ANSIColourTable;
  636.             Colour12    = ANSIColours;
  637.  
  638.             break;
  639.  
  640.         case COLOUR_SIXTEEN:
  641.  
  642.             Table        = EGAColourTable;
  643.             Colour12    = EGAColours;
  644.  
  645.             break;
  646.  
  647.         case COLOUR_AMIGA:
  648.  
  649.             Table        = DefaultColourTable;
  650.             Colour12    = DefaultColours;
  651.  
  652.             break;
  653.  
  654.         case COLOUR_MONO:
  655.  
  656.             Table        = MonoColourTable;
  657.             Colour12    = AtomicColours;
  658.             break;
  659.     }
  660.  
  661.     if(Table)
  662.     {
  663.         CopyMem(&Table -> Entry[0],SomeConfig -> ScreenConfig -> Colours96,Table -> NumColours * sizeof(ColourEntry));
  664.  
  665.         CopyMem(Colour12,SomeConfig -> ScreenConfig -> Colours,16 * sizeof(UWORD));
  666.  
  667.         SomeConfig -> ScreenConfig -> UseColours96 = TRUE;
  668.     }
  669.     else
  670.     {
  671.         CopyMem(Colour12,SomeConfig -> ScreenConfig -> Colours,16 * sizeof(UWORD));
  672.  
  673.         SomeConfig -> ScreenConfig -> UseColours96 = FALSE;
  674.     }
  675. }
  676.  
  677.     /* PaletteSetup():
  678.      *
  679.      *    Set up colour palettes.
  680.      */
  681.  
  682. VOID __regargs
  683. PaletteSetup(struct Configuration *SomeConfig)
  684. {
  685.     WORD i;
  686.  
  687.     if(!SomeConfig)
  688.         SomeConfig = Config;
  689.  
  690.     if(SomeConfig -> ScreenConfig -> UseColours96)
  691.     {
  692.         Colour96x12(SomeConfig -> ScreenConfig -> Colours96,NormalColours,16);
  693.         Colour96x12(SomeConfig -> ScreenConfig -> Colours96,SomeConfig -> ScreenConfig -> Colours,16);
  694.     }
  695.     else
  696.     {
  697.         CopyMem(SomeConfig -> ScreenConfig -> Colours,NormalColours,16 * sizeof(UWORD));
  698.  
  699.         Colour12x96(NormalColours,SomeConfig -> ScreenConfig -> Colours96,16);
  700.  
  701.         SomeConfig -> ScreenConfig -> UseColours96 = TRUE;
  702.     }
  703.  
  704.     CopyMem(NormalColours,&NormalColours[16],16 * sizeof(UWORD));
  705.     CopyMem(NormalColours,BlinkColours,32 * sizeof(UWORD));
  706.  
  707.     switch(SomeConfig -> ScreenConfig -> ColourMode)
  708.     {
  709.         case COLOUR_EIGHT:
  710.  
  711.             if(SomeConfig -> ScreenConfig -> Blinking)
  712.             {
  713.                 for(i = 0 ; i < 8 ; i++)
  714.                     BlinkColours[8 + i] = BlinkColours[0];
  715.  
  716.                 PaletteSize = 16;
  717.             }
  718.             else
  719.                 PaletteSize = 8;
  720.  
  721.             break;
  722.  
  723.         case COLOUR_SIXTEEN:
  724.  
  725.             if(GetBitMapDepth(Window -> WScreen -> RastPort . BitMap) >= 5 && SomeConfig -> ScreenConfig -> Blinking)
  726.             {
  727.                 for(i = 0 ; i < 16 ; i++)
  728.                     BlinkColours[16 + i] = BlinkColours[0];
  729.  
  730.                 PaletteSize = 32;
  731.             }
  732.             else
  733.                 PaletteSize = 16;
  734.  
  735.             break;
  736.  
  737.         case COLOUR_AMIGA:
  738.  
  739.             BlinkColours[3] = BlinkColours[0];
  740.  
  741.             PaletteSize = 4;
  742.  
  743.             break;
  744.  
  745.         case COLOUR_MONO:
  746.  
  747.             PaletteSize = 2;
  748.             break;
  749.     }
  750.  
  751.     if(Kick30)
  752.     {
  753.         if(NormalColourTable)
  754.             DeleteColourTable(NormalColourTable);
  755.  
  756.         if(BlinkColourTable)
  757.             DeleteColourTable(BlinkColourTable);
  758.  
  759.         if(NormalColourTable = CreateColourTable(PaletteSize,NULL,SomeConfig -> ScreenConfig -> Colours96))
  760.         {
  761.             if(PaletteSize == 2 || !SomeConfig -> ScreenConfig -> Blinking)
  762.                 BlinkColourTable = NULL;
  763.             else
  764.             {
  765.                 if(BlinkColourTable = CreateColourTable(PaletteSize,NULL,NULL))
  766.                 {
  767.                     switch(SomeConfig -> ScreenConfig -> ColourMode)
  768.                     {
  769.                         case COLOUR_EIGHT:
  770.  
  771.                             CopyMem(&NormalColourTable -> Entry[0],&NormalColourTable -> Entry[8],8 * sizeof(ColourEntry));
  772.                             CopyMem(&NormalColourTable -> Entry[0],&BlinkColourTable -> Entry[0],16 * sizeof(ColourEntry));
  773.  
  774.                             for(i = 1 ; i < 8 ; i++)
  775.                                 BlinkColourTable -> Entry[8 + i] = BlinkColourTable -> Entry[0];
  776.  
  777.                             break;
  778.  
  779.                         case COLOUR_SIXTEEN:
  780.  
  781.                             if(GetBitMapDepth(Window -> WScreen -> RastPort . BitMap) >= 5)
  782.                             {
  783.                                 CopyMem(&NormalColourTable -> Entry[0],&NormalColourTable -> Entry[16],16 * sizeof(ColourEntry));
  784.                                 CopyMem(&NormalColourTable -> Entry[0],&BlinkColourTable -> Entry[0],32 * sizeof(ColourEntry));
  785.  
  786.                                 for(i = 1 ; i < 16 ; i++)
  787.                                     BlinkColourTable -> Entry[16 + i] = BlinkColourTable -> Entry[0];
  788.                             }
  789.                             else
  790.                             {
  791.                                 DeleteColourTable(BlinkColourTable);
  792.  
  793.                                 BlinkColourTable = NULL;
  794.                             }
  795.  
  796.                             break;
  797.  
  798.                         case COLOUR_AMIGA:
  799.  
  800.                             CopyMem(&NormalColourTable -> Entry[0],&BlinkColourTable -> Entry[0],4 * sizeof(ColourEntry));
  801.  
  802.                             BlinkColourTable -> Entry[3] = BlinkColourTable -> Entry[0];
  803.  
  804.                             break;
  805.                     }
  806.                 }
  807.                 else
  808.                 {
  809.                     DeleteColourTable(NormalColourTable);
  810.  
  811.                     NormalColourTable = NULL;
  812.                 }
  813.             }
  814.         }
  815.     }
  816. }
  817.  
  818.     /* ResetCursorKeys(struct CursorKeys *Keys):
  819.      *
  820.      *    Reset cursor key assignments to defaults.
  821.      */
  822.  
  823. VOID __regargs
  824. ResetCursorKeys(struct CursorKeys *Keys)
  825. {
  826.     STATIC STRPTR Defaults[4] =
  827.     {
  828.         "\\e[A",
  829.         "\\e[B",
  830.         "\\e[C",
  831.         "\\e[D"
  832.     };
  833.  
  834.     WORD i,j;
  835.  
  836.     for(i = 0 ; i < 4 ; i++)
  837.     {
  838.         for(j = 0 ; j < 4 ; j++)
  839.             strcpy(Keys -> Keys[j][i],Defaults[i]);
  840.     }
  841. }
  842.  
  843.     /* ResetMacroKeys(struct MacroKeys *Keys):
  844.      *
  845.      *    Reset the macro key assignments to defaults.
  846.      */
  847.  
  848. STATIC VOID __regargs
  849. ResetMacroKeys(struct MacroKeys *Keys)
  850. {
  851.     STATIC STRPTR FunctionKeyCodes[4] =
  852.     {
  853.         "\\eOP",
  854.         "\\eOQ",
  855.         "\\eOR",
  856.         "\\eOS"
  857.     };
  858.  
  859.     WORD i;
  860.  
  861.     memset(Keys,0,sizeof(struct MacroKeys));
  862.  
  863.     for(i = 0 ; i < 4 ; i++)
  864.         strcpy(Keys -> Keys[1][i],FunctionKeyCodes[i]);
  865. }
  866.  
  867.     /* ScreenSizeStuff():
  868.      *
  869.      *    Set up the terminal screen size.
  870.      */
  871.  
  872. VOID
  873. ScreenSizeStuff()
  874. {
  875.     ObtainSemaphore(&TerminalSemaphore);
  876.  
  877.         /* Is this really the built-in emulation? */
  878.  
  879.     if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  880.     {
  881.         LONG    MaxColumns    = WindowWidth / TextFontWidth,
  882.             MaxLines    = WindowHeight / TextFontHeight,
  883.             Columns,
  884.             Lines;
  885.  
  886.             /* Drop the text area marker. */
  887.  
  888.         if(Marking)
  889.             DropMarker();
  890.  
  891.             /* Turn off the cursor. */
  892.  
  893.         ClearCursor();
  894.  
  895.             /* Set up the new screen width. */
  896.  
  897.         if(Config -> TerminalConfig -> NumColumns < 20)
  898.             Columns = MaxColumns;
  899.         else
  900.             Columns = Config -> TerminalConfig -> NumColumns;
  901.  
  902.             /* Set up the new screen height. */
  903.  
  904.         if(Config -> TerminalConfig -> NumLines < 20)
  905.             Lines = MaxLines;
  906.         else
  907.             Lines = Config -> TerminalConfig -> NumLines;
  908.  
  909.             /* More columns than we will be able to display? */
  910.  
  911.         if(Columns > MaxColumns)
  912.             Columns = MaxColumns;
  913.  
  914.             /* More lines than we will be able to display? */
  915.  
  916.         if(Lines > MaxLines)
  917.             Lines = MaxLines;
  918.  
  919.             /* Set up the central data. */
  920.  
  921.         LastColumn    = Columns - 1;
  922.         LastLine    = Lines - 1;
  923.         LastPixel    = MUL_X(Columns) - 1;
  924.  
  925.             /* Are we to clear the margin? */
  926.  
  927.         if(Columns < MaxColumns || Lines < MaxLines)
  928.         {
  929.                 /* Save the rendering attributes. */
  930.  
  931.             BackupRender();
  932.  
  933.                 /* Set the defaults. */
  934.  
  935.             SetAPen(RPort,BgPen = MappedPens[0][PenTable[0]]);
  936.  
  937.             SetMask(RPort,DepthMask);
  938.  
  939.                 /* Clear remaining columns. */
  940.  
  941.             if(Columns < MaxColumns)
  942.                 ScrollLineRectFill(RPort,MUL_X(LastColumn + 1),0,WindowWidth - 1,WindowHeight - 1);
  943.  
  944.                 /* Clear remaining lines. */
  945.  
  946.             if(Lines < MaxLines)
  947.                 ScrollLineRectFill(RPort,0,MUL_Y(LastLine + 1),WindowWidth - 1,WindowHeight - 1);
  948.  
  949.                 /* Restore rendering attributes. */
  950.  
  951.             BackupRender();
  952.         }
  953.  
  954.             /* Truncate illegal cursor position. */
  955.  
  956.         if(CursorY > LastLine)
  957.             CursorY = LastLine;
  958.  
  959.         ConFontScaleUpdate();
  960.  
  961.             /* Truncate illegal cursor position. */
  962.  
  963.         if(CursorX > LastPrintableColumn)
  964.             CursorX = LastPrintableColumn;
  965.  
  966.             /* Fix scroll region button. */
  967.  
  968.         if(!RegionSet)
  969.             Bottom = LastLine;
  970.  
  971.             /* Turn the cursor back on. */
  972.  
  973.         DrawCursor();
  974.     }
  975.  
  976.     FixScreenSize = FALSE;
  977.  
  978.     ReleaseSemaphore(&TerminalSemaphore);
  979. }
  980.  
  981.     /* PubScreenStuff():
  982.      *
  983.      *    This part handles the public screen setup stuff.
  984.      */
  985.  
  986. VOID
  987. PubScreenStuff()
  988. {
  989.     if(Screen)
  990.     {
  991.             /* Are we to make our screen public? */
  992.  
  993.         if(Config -> ScreenConfig -> MakeScreenPublic)
  994.             PubScreenStatus(Screen,NULL);
  995.         else
  996.             PubScreenStatus(Screen,PSNF_PRIVATE);
  997.  
  998.             /* Are we to `shanghai' Workbench windows? */
  999.  
  1000.         if(Config -> ScreenConfig -> ShanghaiWindows)
  1001.         {
  1002.             PublicModes |= SHANGHAI;
  1003.  
  1004.             SetPubScreenModes(PublicModes);
  1005.  
  1006.                 /* Make this the default public screen. */
  1007.  
  1008.             SetDefaultPubScreen(TermIDString);
  1009.         }
  1010.         else
  1011.         {
  1012.             PublicModes &= ~SHANGHAI;
  1013.  
  1014.             if(LockPubScreen(DefaultPubScreenName))
  1015.             {
  1016.                 SetDefaultPubScreen(DefaultPubScreenName);
  1017.  
  1018.                 UnlockPubScreen(DefaultPubScreenName,NULL);
  1019.             }
  1020.             else
  1021.                 SetDefaultPubScreen(NULL);
  1022.  
  1023.             SetPubScreenModes(PublicModes);
  1024.         }
  1025.     }
  1026.  
  1027.     FixPubScreenMode = FALSE;
  1028. }
  1029.  
  1030.     /* ConfigSetup():
  1031.      *
  1032.      *    Compare the current configuration with the
  1033.      *    last backup and reset the serial device, terminal,
  1034.      *    etc. if necessary.
  1035.      */
  1036.  
  1037. VOID
  1038. ConfigSetup()
  1039. {
  1040.     BYTE RasterWasEnabled = RasterEnabled;
  1041.  
  1042.         /* Hide or show the upload queue icon. */
  1043.  
  1044.     ToggleUploadQueueIcon(Config -> TransferConfig -> HideUploadIcon);
  1045.  
  1046.         /* Take care of the end-of-line translation. */
  1047.  
  1048.     Update_CR_LF_Translation();
  1049.  
  1050.         /* First we will take a look at the configuration
  1051.          * and try to find those parts which have changed
  1052.          * and require the main screen display to be
  1053.          * reopened.
  1054.          */
  1055.  
  1056.     if(PrivateConfig -> ScreenConfig -> FontHeight != Config -> ScreenConfig -> FontHeight)
  1057.         ResetDisplay = TRUE;
  1058.  
  1059.     if((PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL) || (PrivateConfig -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL))
  1060.         ResetDisplay = TRUE;
  1061.  
  1062.     if(PrivateConfig -> ScreenConfig -> SplitStatus != Config -> ScreenConfig -> SplitStatus)
  1063.         ResetDisplay = TRUE;
  1064.  
  1065.     if(PrivateConfig -> ScreenConfig -> ShareScreen != Config -> ScreenConfig -> ShareScreen)
  1066.         ResetDisplay = TRUE;
  1067.  
  1068.     if(PrivateConfig -> ScreenConfig -> Depth != Config -> ScreenConfig -> Depth || PrivateConfig -> ScreenConfig -> OverscanType != Config -> ScreenConfig -> OverscanType)
  1069.         ResetDisplay = TRUE;
  1070.  
  1071.     if(PrivateConfig -> ScreenConfig -> DisplayWidth != Config -> ScreenConfig -> DisplayWidth || PrivateConfig -> ScreenConfig -> DisplayHeight != Config -> ScreenConfig -> DisplayHeight)
  1072.         ResetDisplay = TRUE;
  1073.  
  1074.     if(Stricmp(PrivateConfig -> ScreenConfig -> FontName,Config -> ScreenConfig -> FontName))
  1075.         ResetDisplay = TRUE;
  1076.  
  1077.     if(PrivateConfig -> TerminalConfig -> FontMode != Config -> TerminalConfig -> FontMode)
  1078.         ResetDisplay = TRUE;
  1079.  
  1080.     if(PrivateConfig -> TerminalConfig -> UseTerminalTask != Config -> TerminalConfig -> UseTerminalTask)
  1081.         ResetDisplay = TRUE;
  1082.  
  1083.     if(PrivateConfig -> TerminalConfig -> TextFontHeight != Config -> TerminalConfig -> TextFontHeight)
  1084.         ResetDisplay = TRUE;
  1085.  
  1086.     if(Stricmp(PrivateConfig -> TerminalConfig -> TextFontName,Config -> TerminalConfig -> TextFontName))
  1087.         ResetDisplay = TRUE;
  1088.  
  1089.     if(PrivateConfig -> ScreenConfig -> DisplayMode != Config -> ScreenConfig -> DisplayMode || PrivateConfig -> ScreenConfig -> ColourMode != Config -> ScreenConfig -> ColourMode)
  1090.         ResetDisplay = TRUE;
  1091.  
  1092.     if(PrivateConfig -> TerminalConfig -> IBMFontHeight != Config -> TerminalConfig -> IBMFontHeight)
  1093.         ResetDisplay = TRUE;
  1094.  
  1095.     if(Stricmp(PrivateConfig -> TerminalConfig -> IBMFontName,Config -> TerminalConfig -> IBMFontName))
  1096.         ResetDisplay = TRUE;
  1097.  
  1098.     if((PrivateConfig -> ScreenConfig -> ColourMode == Config -> ScreenConfig -> ColourMode) && (PrivateConfig -> ScreenConfig -> ColourMode == COLOUR_EIGHT || PrivateConfig -> ScreenConfig -> ColourMode == COLOUR_SIXTEEN))
  1099.     {
  1100.         if(PrivateConfig -> ScreenConfig -> Blinking != Config -> ScreenConfig -> Blinking)
  1101.             ResetDisplay = TRUE;
  1102.     }
  1103.  
  1104.     if(Kick30)
  1105.     {
  1106.         if(Config -> ScreenConfig -> UsePens != PrivateConfig -> ScreenConfig -> UsePens || memcmp(Config -> ScreenConfig -> PenArray,PrivateConfig -> ScreenConfig -> PenArray,sizeof(UWORD) * 12))
  1107.             ResetDisplay = TRUE;
  1108.     }
  1109.  
  1110.     if(Config -> ScreenConfig -> Depth != PrivateConfig -> ScreenConfig -> Depth)
  1111.         ResetDisplay = TRUE;
  1112.  
  1113.     if(PrivateConfig -> ScreenConfig -> FasterLayout != Config -> ScreenConfig -> FasterLayout)
  1114.         ResetDisplay = TRUE;
  1115.  
  1116.     if(PrivateConfig -> ScreenConfig -> StatusLine != Config -> ScreenConfig -> StatusLine)
  1117.         ResetDisplay = TRUE;
  1118.  
  1119.     if(PrivateConfig -> ScreenConfig -> TitleBar != Config -> ScreenConfig -> TitleBar)
  1120.         ResetDisplay = TRUE;
  1121.  
  1122.     if(PrivateConfig -> ScreenConfig -> UseWorkbench != Config -> ScreenConfig -> UseWorkbench)
  1123.         ResetDisplay = TRUE;
  1124.  
  1125.     if(strcmp(PrivateConfig -> ScreenConfig -> PubScreenName,Config -> ScreenConfig -> PubScreenName) && Config -> ScreenConfig -> UseWorkbench)
  1126.         ResetDisplay = TRUE;
  1127.  
  1128.     if(PrivateConfig -> EmulationConfig -> UseStandardPens != Config -> EmulationConfig -> UseStandardPens)
  1129.         ResetDisplay = TRUE;
  1130.  
  1131.     if(!Config -> EmulationConfig -> UseStandardPens && (memcmp(Config -> EmulationConfig -> Pens,PrivateConfig -> EmulationConfig -> Pens,sizeof(Config -> EmulationConfig -> Pens)) || memcmp(Config -> EmulationConfig -> Attributes,PrivateConfig -> EmulationConfig -> Attributes,sizeof(Config -> EmulationConfig -> Attributes))))
  1132.         ResetDisplay = TRUE;
  1133.  
  1134.         /* Now for the `harmless' actions which do not
  1135.          * require to change the screen or other
  1136.          * rendering data.
  1137.          */
  1138.  
  1139.     if(!ResetDisplay)
  1140.     {
  1141.         if(PrivateConfig -> TerminalConfig -> NumColumns != Config -> TerminalConfig -> NumColumns || PrivateConfig -> TerminalConfig -> NumLines != Config -> TerminalConfig -> NumLines)
  1142.         {
  1143.             if(Config -> ScreenConfig -> UseWorkbench)
  1144.             {
  1145.                 UWORD    Width,
  1146.                     Height;
  1147.  
  1148.                 if(Config -> TerminalConfig -> NumColumns < 20)
  1149.                     Width = ScreenWidth;
  1150.                 else
  1151.                     Width = Window -> BorderLeft + TextFontWidth * Config -> TerminalConfig -> NumColumns + Window -> BorderRight;
  1152.  
  1153.                 if(Config -> TerminalConfig -> NumLines < 20)
  1154.                     Height = ScreenHeight;
  1155.                 else
  1156.                     Height = Window -> BorderTop + TextFontHeight * Config -> TerminalConfig -> NumLines + Window -> BorderBottom;
  1157.  
  1158.                 ChangeWindowBox(Window,Window -> LeftEdge,Window -> TopEdge,Width,Height);
  1159.  
  1160.                 FixScreenSize = TRUE;
  1161.             }
  1162.             else
  1163.                 ResetDisplay = TRUE;
  1164.         }
  1165.     }
  1166.  
  1167.     if(PrivateConfig -> ScreenConfig -> MakeScreenPublic != Config -> ScreenConfig -> MakeScreenPublic || PrivateConfig -> ScreenConfig -> ShanghaiWindows != Config -> ScreenConfig -> ShanghaiWindows)
  1168.         PubScreenStuff();
  1169.  
  1170.     if(PrivateConfig -> ScreenConfig -> ColourMode == Config -> ScreenConfig -> ColourMode && (memcmp(PrivateConfig -> ScreenConfig -> Colours,Config -> ScreenConfig -> Colours,sizeof(UWORD) * 16) || memcmp(PrivateConfig -> ScreenConfig -> Colours96,Config -> ScreenConfig -> Colours96,sizeof(ColourEntry) * 16)))
  1171.         Current2DefaultPalette(Config);
  1172.  
  1173.         /* Are we to load a new transfer library? */
  1174.  
  1175.     if(Config -> TransferConfig -> DefaultLibrary[0] && strcmp(PrivateConfig -> TransferConfig -> DefaultLibrary,Config -> TransferConfig -> DefaultLibrary))
  1176.     {
  1177.         strcpy(LastXprLibrary,Config -> TransferConfig -> DefaultLibrary);
  1178.  
  1179.         ProtocolSetup(FALSE);
  1180.     }
  1181.  
  1182.         /* No custom keymap this time? */
  1183.  
  1184.     if(!Config -> TerminalConfig -> KeyMapFileName[0])
  1185.     {
  1186.         KeyMap = NULL;
  1187.  
  1188.         if(KeySegment)
  1189.         {
  1190.             UnLoadSeg(KeySegment);
  1191.  
  1192.             KeySegment = NULL;
  1193.         }
  1194.     }
  1195.     else
  1196.     {
  1197.             /* Check whether the keymap name has changed. */
  1198.  
  1199.         if(strcmp(PrivateConfig -> TerminalConfig -> KeyMapFileName,Config -> TerminalConfig -> KeyMapFileName))
  1200.             KeyMap = LoadKeyMap(Config -> TerminalConfig -> KeyMapFileName);
  1201.     }
  1202.  
  1203.         /* Are we to load the keyboard macro settings? */
  1204.  
  1205.     if(Config -> FileConfig -> MacroFileName[0] && Stricmp(PrivateConfig -> FileConfig -> MacroFileName,Config -> FileConfig -> MacroFileName))
  1206.     {
  1207.         if(!LoadMacros(Config -> FileConfig -> MacroFileName,MacroKeys))
  1208.             ResetMacroKeys(MacroKeys);
  1209.         else
  1210.             strcpy(LastMacros,Config -> FileConfig -> MacroFileName);
  1211.     }
  1212.  
  1213.         /* Are we to load the cursor key settings? */
  1214.  
  1215.     if(Config -> FileConfig -> CursorFileName[0] && Stricmp(PrivateConfig -> FileConfig -> CursorFileName,Config -> FileConfig -> CursorFileName))
  1216.     {
  1217.         if(!ReadIFFData(Config -> FileConfig -> CursorFileName,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  1218.             ResetCursorKeys(CursorKeys);
  1219.         else
  1220.             strcpy(LastCursorKeys,Config -> FileConfig -> CursorFileName);
  1221.     }
  1222.  
  1223.         /* Are we to load the translation tables? */
  1224.  
  1225.     if(Config -> FileConfig -> TranslationFileName[0] && Stricmp(PrivateConfig -> FileConfig -> TranslationFileName,Config -> FileConfig -> TranslationFileName))
  1226.     {
  1227.         if(SendTable)
  1228.         {
  1229.             FreeTranslationTable(SendTable);
  1230.  
  1231.             SendTable = NULL;
  1232.         }
  1233.  
  1234.         if(ReceiveTable)
  1235.         {
  1236.             FreeTranslationTable(ReceiveTable);
  1237.  
  1238.             ReceiveTable = NULL;
  1239.         }
  1240.  
  1241.         if(SendTable = AllocTranslationTable())
  1242.         {
  1243.             if(ReceiveTable = AllocTranslationTable())
  1244.             {
  1245.                 if(LoadTranslationTables(Config -> FileConfig -> TranslationFileName,SendTable,ReceiveTable))
  1246.                 {
  1247.                     strcpy(LastTranslation,Config -> FileConfig -> TranslationFileName);
  1248.  
  1249.                     if(IsStandardTable(SendTable) && IsStandardTable(ReceiveTable))
  1250.                     {
  1251.                         FreeTranslationTable(SendTable);
  1252.  
  1253.                         SendTable = NULL;
  1254.  
  1255.                         FreeTranslationTable(ReceiveTable);
  1256.  
  1257.                         ReceiveTable = NULL;
  1258.                     }
  1259.                 }
  1260.                 else
  1261.                 {
  1262.                     FreeTranslationTable(SendTable);
  1263.  
  1264.                     SendTable = NULL;
  1265.  
  1266.                     FreeTranslationTable(ReceiveTable);
  1267.  
  1268.                     ReceiveTable = NULL;
  1269.                 }
  1270.             }
  1271.             else
  1272.             {
  1273.                 FreeTranslationTable(SendTable);
  1274.  
  1275.                 SendTable = NULL;
  1276.             }
  1277.         }
  1278.     }
  1279.  
  1280.         /* Update the text sending functions. */
  1281.  
  1282.     SendSetup();
  1283.  
  1284.         /* Are we to load the fast macro settings? */
  1285.  
  1286.     if(Config -> FileConfig -> FastMacroFileName[0] && Stricmp(PrivateConfig -> FileConfig -> FastMacroFileName,Config -> FileConfig -> FastMacroFileName))
  1287.     {
  1288.         if(FastWindow)
  1289.             LT_LockWindow(FastWindow);
  1290.  
  1291.         FreeList(&FastMacroList);
  1292.  
  1293.         if(LoadFastMacros(Config -> FileConfig -> FastMacroFileName,&FastMacroList))
  1294.             strcpy(LastFastMacros,Config -> FileConfig -> FastMacroFileName);
  1295.  
  1296.         if(FastWindow)
  1297.         {
  1298.             RefreshFastWindow(TRUE);
  1299.  
  1300.             LT_UnlockWindow(FastWindow);
  1301.         }
  1302.     }
  1303.  
  1304.         /* Serial configuration needs updating? */
  1305.  
  1306.     ReconfigureSerial(Window,NULL);
  1307.  
  1308.         /* Are we to open the fast macro panel? */
  1309.  
  1310.     if(Config -> MiscConfig -> OpenFastMacroPanel)
  1311.         HadFastMacros = TRUE;
  1312.  
  1313.         /* Are we to freeze the text buffer? */
  1314.  
  1315.     if(!Config -> CaptureConfig -> BufferEnabled)
  1316.         BufferFrozen = TRUE;
  1317.  
  1318.         /* Now for the actions which require that the
  1319.          * screen stays open.
  1320.          */
  1321.  
  1322.     if(!ResetDisplay)
  1323.     {
  1324.         if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1325.         {
  1326.             if(PrivateConfig -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL || (Config -> TerminalConfig -> EmulationFileName[0] && strcmp(PrivateConfig -> TerminalConfig -> EmulationFileName,Config -> TerminalConfig -> EmulationFileName)))
  1327.             {
  1328.                 if(!OpenEmulator(Config -> TerminalConfig -> EmulationFileName))
  1329.                 {
  1330.                     Config -> TerminalConfig -> EmulationMode = EMULATION_ANSIVT100;
  1331.  
  1332.                     ResetDisplay = TRUE;
  1333.  
  1334.                     RasterEnabled = TRUE;
  1335.  
  1336.                     MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Config -> TerminalConfig -> EmulationFileName);
  1337.                 }
  1338.                 else
  1339.                     RasterEnabled = FALSE;
  1340.             }
  1341.         }
  1342.         else
  1343.         {
  1344.             if(XEmulatorBase && PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1345.             {
  1346.                 XEmulatorClearConsole(XEM_IO);
  1347.  
  1348.                 CloseEmulator();
  1349.  
  1350.                 RasterEnabled = TRUE;
  1351.  
  1352.                 ClearCursor();
  1353.  
  1354.                 Reset();
  1355.  
  1356.                 DrawCursor();
  1357.             }
  1358.             else
  1359.                 RasterEnabled = TRUE;
  1360.         }
  1361.  
  1362.         if(RasterEnabled != RasterWasEnabled)
  1363.             RasterEraseScreen(2);
  1364.  
  1365.         if(!Config -> ScreenConfig -> UseWorkbench && !SharedScreen)
  1366.         {
  1367.             PaletteSetup(Config);
  1368.  
  1369.             LoadColourTable(VPort,NormalColourTable,NormalColours,PaletteSize);
  1370.         }
  1371.  
  1372.         if(Config -> MiscConfig -> OpenFastMacroPanel && !FastWindow)
  1373.             OpenFastWindow();
  1374.  
  1375.         PubScreenStuff();
  1376.  
  1377.         if(Menu)
  1378.         {
  1379.             CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  1380.  
  1381.             if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0])
  1382.                 OffItem(MEN_CHAT_LINE);
  1383.             else
  1384.                 CheckItem(MEN_CHAT_LINE,ChatMode);
  1385.  
  1386.             if(!XProtocolBase)
  1387.                 SetTransferMenu(FALSE);
  1388.             else
  1389.                 SetTransferMenu(TRUE);
  1390.  
  1391.             SetRasterMenu(RasterEnabled);
  1392.  
  1393.                 /* Disable the dialing functions if online. */
  1394.  
  1395.             ObtainSemaphore(&OnlineSemaphore);
  1396.  
  1397.             if(Online)
  1398.                 SetDialMenu(FALSE);
  1399.             else
  1400.                 SetDialMenu(TRUE);
  1401.  
  1402.             ReleaseSemaphore(&OnlineSemaphore);
  1403.         }
  1404.  
  1405.         Blocking = FALSE;
  1406.     }
  1407.     else
  1408.     {
  1409.             /* Are we no longer to use the external emulator? */
  1410.  
  1411.         if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  1412.         {
  1413.             if(XEmulatorBase && PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1414.             {
  1415.                 XEmulatorClearConsole(XEM_IO);
  1416.  
  1417.                 CloseEmulator();
  1418.             }
  1419.         }
  1420.  
  1421.         RasterEnabled = TRUE;
  1422.     }
  1423.  
  1424.         /* Change the task priority. */
  1425.  
  1426.     SetTaskPri(ThisProcess,(LONG)Config -> MiscConfig -> Priority);
  1427.  
  1428.     ConOutputUpdate();
  1429.  
  1430.     ConFontScaleUpdate();
  1431.  
  1432.     ConProcessUpdate();
  1433.  
  1434.         /* Reset the scanner. */
  1435.  
  1436.     FlowInit(TRUE);
  1437. }
  1438.  
  1439.     /* DisplayReset():
  1440.      *
  1441.      *    Reset the entire display if necessary.
  1442.      */
  1443.  
  1444. BYTE
  1445. DisplayReset()
  1446. {
  1447.     UBYTE    *Result;
  1448.     BYTE     Success = TRUE;
  1449.  
  1450.         /* Delete the display (if possible).
  1451.          * This will go wrong if there
  1452.          * are any visitor windows on our
  1453.          * screen.
  1454.          */
  1455.  
  1456.     if(DeleteDisplay())
  1457.     {
  1458.         if(Result = CreateDisplay(FALSE))
  1459.         {
  1460.             DeleteDisplay();
  1461.  
  1462.             MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Result);
  1463.  
  1464.             Success = FALSE;
  1465.         }
  1466.         else
  1467.         {
  1468.             BumpWindow(Window);
  1469.  
  1470.             PubScreenStuff();
  1471.  
  1472.             DisplayReopened = TRUE;
  1473.         }
  1474.     }
  1475.     else
  1476.     {
  1477.         SaveConfig(PrivateConfig,Config);
  1478.  
  1479.         BlockWindows();
  1480.  
  1481.         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_TERMMAIN_CANNOT_CLOSE_SCREEN_YET_TXT));
  1482.  
  1483.         ReleaseWindows();
  1484.  
  1485.         Success = TRUE;
  1486.     }
  1487.  
  1488.     ResetDisplay = FALSE;
  1489.  
  1490.         /* Prepare for the worst case... */
  1491.  
  1492.     if(Success)
  1493.         Apocalypse = FALSE;
  1494.     else
  1495.         MainTerminated = Apocalypse = TRUE;
  1496.  
  1497.     return(Success);
  1498. }
  1499.  
  1500.     /* DeleteDisplay():
  1501.      *
  1502.      *    Free all resources associated with the terminal
  1503.      *    display (tasks, interrupts, screen, window, etc.).
  1504.      */
  1505.  
  1506. BYTE
  1507. DeleteDisplay()
  1508. {
  1509.     struct Screen *WhichScreen;
  1510.  
  1511.     if(SharedScreen)
  1512.         WhichScreen = SharedScreen;
  1513.     else
  1514.         WhichScreen = Screen;
  1515.  
  1516.     if(WhichScreen)
  1517.     {
  1518.         if(!(PubScreenStatus(WhichScreen,PSNF_PRIVATE) & PSNF_PRIVATE))
  1519.             return(FALSE);
  1520.     }
  1521.  
  1522.     GuideCleanup();
  1523.  
  1524.     DeleteLED();
  1525.  
  1526.     CloseQueueWindow();
  1527.  
  1528.     if(StatusProcess)
  1529.     {
  1530.         Forbid();
  1531.  
  1532.         Signal(StatusProcess,SIG_KILL);
  1533.  
  1534.         ClrSignal(SIG_HANDSHAKE);
  1535.  
  1536.         Wait(SIG_HANDSHAKE);
  1537.  
  1538.         Permit();
  1539.  
  1540.         StatusProcess = NULL;
  1541.     }
  1542.  
  1543.     if(Marking)
  1544.         FreeMarker();
  1545.  
  1546.     FirstClick    = TRUE;
  1547.     HoldClick    = FALSE;
  1548.  
  1549.     CloseInfoWindow();
  1550.  
  1551.     DeleteReview();
  1552.  
  1553.     DeleteEmulationProcess();
  1554.  
  1555.     if(Config)
  1556.     {
  1557.         if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && XEmulatorBase)
  1558.             CloseEmulator();
  1559.     }
  1560.  
  1561.     DeleteRaster();
  1562.  
  1563.     DeleteScale();
  1564.  
  1565.     if(TabStops)
  1566.     {
  1567.         FreeVecPooled(TabStops);
  1568.  
  1569.         TabStops = NULL;
  1570.     }
  1571.  
  1572.     if(ScrollLines)
  1573.     {
  1574.         FreeVecPooled(ScrollLines);
  1575.  
  1576.         ScrollLines = NULL;
  1577.     }
  1578.  
  1579.     if(Screen)
  1580.         ScreenToBack(Screen);
  1581.  
  1582.     if(FastWindow)
  1583.     {
  1584.         HadFastMacros = TRUE;
  1585.  
  1586.         CloseFastWindow();
  1587.     }
  1588.     else
  1589.         HadFastMacros = FALSE;
  1590.  
  1591.         /* Clean up the menu glyphs. */
  1592.  
  1593.     DisposeObject(AmigaGlyph);
  1594.  
  1595.     AmigaGlyph = NULL;
  1596.  
  1597.     DisposeObject(CheckGlyph);
  1598.  
  1599.     CheckGlyph = NULL;
  1600.  
  1601.     if(StatusWindow)
  1602.     {
  1603.         ClearMenuStrip(StatusWindow);
  1604.         CloseWindowSafely(StatusWindow);
  1605.  
  1606.         StatusWindow = NULL;
  1607.     }
  1608.  
  1609.     if(DefaultPubScreen)
  1610.     {
  1611.         UnlockPubScreen(NULL,DefaultPubScreen);
  1612.  
  1613.         DefaultPubScreen = NULL;
  1614.     }
  1615.  
  1616.         /* Remove AppWindow link. */
  1617.  
  1618.     if(WorkbenchWindow)
  1619.     {
  1620.         RemoveAppWindow(WorkbenchWindow);
  1621.  
  1622.         WorkbenchWindow = NULL;
  1623.     }
  1624.  
  1625.         /* Remove AppWindow port and any pending messages. */
  1626.  
  1627.     if(WorkbenchPort)
  1628.     {
  1629.         struct Message *Message;
  1630.  
  1631.         while(Message = GetMsg(WorkbenchPort))
  1632.             ReplyMsg(Message);
  1633.  
  1634.         DeleteMsgPort(WorkbenchPort);
  1635.  
  1636.         WorkbenchPort = NULL;
  1637.     }
  1638.  
  1639.     if(DrawInfo)
  1640.     {
  1641.             /* Release the rendering pens. */
  1642.  
  1643.         FreeScreenDrawInfo(Window -> WScreen,DrawInfo);
  1644.  
  1645.         DrawInfo = NULL;
  1646.     }
  1647.  
  1648.     HideChatGadget();
  1649.  
  1650.     if(Window)
  1651.     {
  1652.         if(!Screen)
  1653.             PutWindowInfo(WINDOW_MAIN,Window -> LeftEdge,Window -> TopEdge,Window -> Width,Window -> Height);
  1654.  
  1655.         if(AllocatedPens && Kick30)
  1656.         {
  1657.             WORD i;
  1658.  
  1659.             ObtainSemaphore(&TerminalSemaphore);
  1660.  
  1661.                 /* Erase the window contents. We will
  1662.                  * want to release any pens we have
  1663.                  * allocated and want to avoid nasty
  1664.                  * flashing and flickering.
  1665.                  */
  1666.  
  1667.             SetAPen(RPort,0);
  1668.  
  1669.             RectFill(RPort,WindowLeft,WindowTop,WindowLeft + WindowWidth - 1,WindowTop + WindowHeight - 1);
  1670.  
  1671.                 /* Release any pens we have allocated. */
  1672.  
  1673.             for(i = 0 ; i < 16 ; i++)
  1674.             {
  1675.                 if(MappedPens[1][i])
  1676.                 {
  1677.                     ReleasePen(VPort -> ColorMap,MappedPens[0][i]);
  1678.  
  1679.                     MappedPens[0][i] = i;
  1680.                     MappedPens[1][i] = FALSE;
  1681.                 }
  1682.             }
  1683.  
  1684.             AllocatedPens = FALSE;
  1685.  
  1686.             ReleaseSemaphore(&TerminalSemaphore);
  1687.         }
  1688.  
  1689.         if(ClipRegion)
  1690.         {
  1691.             InstallClipRegion(Window -> WLayer,OldRegion);
  1692.  
  1693.             DisposeRegion(ClipRegion);
  1694.  
  1695.             ClipRegion = NULL;
  1696.         }
  1697.  
  1698.         ClearMenuStrip(Window);
  1699.  
  1700.         ThisProcess -> pr_WindowPtr = OldWindowPtr;
  1701.  
  1702.         PopWindow();
  1703.  
  1704.         if(TermPort)
  1705.             TermPort -> TopWindow = NULL;
  1706.  
  1707.         LT_DeleteWindowLock(Window);
  1708.  
  1709.         CloseWindow(Window);
  1710.  
  1711.         Window = NULL;
  1712.     }
  1713.  
  1714.     if(Menu)
  1715.     {
  1716. #if 0
  1717.         FreeMenus(Menu);
  1718. #else
  1719.         LT_DisposeMenu(Menu);
  1720. #endif
  1721.         Menu = NULL;
  1722.     }
  1723.  
  1724.     if(VisualInfo)
  1725.     {
  1726.         FreeVisualInfo(VisualInfo);
  1727.  
  1728.         VisualInfo = NULL;
  1729.     }
  1730.  
  1731.     DeletePacketWindow(FALSE);
  1732.  
  1733.     if(UserTextFont)
  1734.     {
  1735.         CloseFont(UserTextFont);
  1736.  
  1737.         UserTextFont = NULL;
  1738.     }
  1739.  
  1740.         /* Before we can close screen we will have to
  1741.          * make sure that it is no longer the default
  1742.          * public screen.
  1743.          */
  1744.  
  1745.     if(Config)
  1746.     {
  1747.         if(Config -> ScreenConfig -> ShanghaiWindows)
  1748.         {
  1749.             if(LockPubScreen(DefaultPubScreenName))
  1750.             {
  1751.                 SetDefaultPubScreen(DefaultPubScreenName);
  1752.  
  1753.                 UnlockPubScreen(DefaultPubScreenName,NULL);
  1754.             }
  1755.             else
  1756.                 SetDefaultPubScreen(NULL);
  1757.         }
  1758.     }
  1759.  
  1760.     if(Screen)
  1761.     {
  1762.         CloseScreen(Screen);
  1763.  
  1764.         Screen = NULL;
  1765.     }
  1766.  
  1767.     if(SharedScreen)
  1768.     {
  1769.         CloseScreen(SharedScreen);
  1770.  
  1771.         SharedScreen = NULL;
  1772.     }
  1773.  
  1774.     if(GFX)
  1775.     {
  1776.         CloseFont(GFX);
  1777.  
  1778.         GFX = NULL;
  1779.     }
  1780.  
  1781.     if(TextFont)
  1782.     {
  1783.         CloseFont(TextFont);
  1784.  
  1785.         TextFont = NULL;
  1786.     }
  1787.  
  1788.     return(TRUE);
  1789. }
  1790.  
  1791. STATIC VOID __regargs
  1792. StatusSizeSetup(struct Screen *Screen,LONG *StatusWidth,LONG *StatusHeight)
  1793. {
  1794.     SZ_SizeSetup(Screen,&UserFont);
  1795.  
  1796.     if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0] && Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && !Config -> ScreenConfig -> SplitStatus)
  1797.     {
  1798.         *StatusHeight = 0;
  1799.  
  1800.         return;
  1801.     }
  1802.  
  1803.     if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED)
  1804.     {
  1805.         if(Config -> ScreenConfig -> StatusLine == STATUSLINE_COMPRESSED)
  1806.         {
  1807.             *StatusWidth    = 80 * UserFontWidth;
  1808.             *StatusHeight    = UserFontHeight;
  1809.  
  1810.             if(Config -> ScreenConfig -> SplitStatus)
  1811.             {
  1812.                 *StatusWidth    += 2;
  1813.                 *StatusHeight    += 2;
  1814.             }
  1815.         }
  1816.         else
  1817.         {
  1818.             LONG    i,Len,Max;
  1819.             UWORD    ColumnLeft[4],
  1820.                 ColumnWidth[4];
  1821.  
  1822.             *StatusWidth    = 0;
  1823.             *StatusHeight    = SZ_BoxHeight(2);
  1824.  
  1825.             ColumnLeft[0] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_STATUS_TXT,MSG_TERMSTATUSDISPLAY_FONT_TXT,-1);
  1826.             ColumnLeft[1] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_PROTOCOL_TXT,MSG_TERMSTATUSDISPLAY_TERMINAL_TXT,-1);
  1827.             ColumnLeft[2] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_BAUDRATE_TXT,MSG_TERMSTATUSDISPLAY_PARAMETERS_TXT,-1);
  1828.             ColumnLeft[3] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_TIME_TXT,MSG_TERMSTATUSDISPLAY_ONLINE_TXT,-1);
  1829.  
  1830.             Max = 0;
  1831.  
  1832.             for(i = MSG_TERMAUX_READY_TXT ; i <= MSG_TERMAUX_HANG_UP_TXT ; i++)
  1833.             {
  1834.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  1835.                     Max = Len;
  1836.             }
  1837.  
  1838.             for(i = MSG_TERMSTATUSDISPLAY_FROZEN_TXT ; i <= MSG_TERMSTATUSDISPLAY_RECORDING_TXT ; i++)
  1839.             {
  1840.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  1841.                     Max = Len;
  1842.             }
  1843.  
  1844.             ColumnWidth[0] = Max;
  1845.  
  1846.             Max = SZ_BoxWidth(12);
  1847.  
  1848.             for(i = MSG_TERMAUX_ANSI_VT102_TXT ; i <= MSG_TERMAUX_HEX_TXT ; i++)
  1849.             {
  1850.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  1851.                     Max = Len;
  1852.             }
  1853.  
  1854.             ColumnWidth[1] = Max;
  1855.  
  1856.             Max = SZ_BoxWidth(10);
  1857.  
  1858.             for(i = MSG_TERMAUX_NONE_TXT ; i <= MSG_TERMAUX_SPACE_TXT ; i++)
  1859.             {
  1860.                 if((Len = SZ_BoxWidth(4 + strlen(LocaleString(i)))) > Max)
  1861.                     Max = Len;
  1862.             }
  1863.  
  1864.             ColumnWidth[2] = Max;
  1865.  
  1866.             ColumnWidth[3] = SZ_BoxWidth(8);
  1867.  
  1868.             for(i = 0 ; i < 4 ; i++)
  1869.                 *StatusWidth += ColumnWidth[i] + ColumnLeft[i];
  1870.  
  1871.             *StatusWidth += 3 * InterWidth;
  1872.  
  1873.             if(!Config -> ScreenConfig -> SplitStatus)
  1874.             {
  1875.                 *StatusWidth    += 2;
  1876.                 *StatusHeight    += 4;
  1877.             }
  1878.             else
  1879.             {
  1880.                 *StatusWidth    += 2;
  1881.                 *StatusHeight    += 2;
  1882.             }
  1883.         }
  1884.     }
  1885.     else
  1886.         *StatusHeight = 0;
  1887. }
  1888.  
  1889.     /* CreateDisplay(BYTE FirstSetup):
  1890.      *
  1891.      *    Open the display and allocate associated data.
  1892.      */
  1893.  
  1894. STRPTR __regargs
  1895. CreateDisplay(BYTE FirstSetup)
  1896. {
  1897.     UWORD            Count = 0,i;
  1898.     LONG            ErrorCode,Top,Height;
  1899.     ULONG            TagArray[9];
  1900.     struct Rectangle    DisplayClip;
  1901.     BYTE            OpenFailed = FALSE,
  1902.                 RealDepth;
  1903.     STRPTR            Error;
  1904.     ULONG            X_DPI,Y_DPI;
  1905.     UWORD            PenArray[16];
  1906.     LONG            StatusWidth,
  1907.                 StatusHeight;
  1908.  
  1909.     BlockNestCount = 0;
  1910.  
  1911.     WeAreBlocking = FALSE;
  1912.  
  1913.     SetQueueDiscard(SpecialQueue,FALSE);
  1914.  
  1915.     TagDPI[0] . ti_Tag = TAG_DONE;
  1916.  
  1917.         /* Don't permit weird settings. */
  1918.  
  1919.     if(!Config -> ScreenConfig -> StatusLine || (!Config -> ScreenConfig -> ShareScreen && !Config -> ScreenConfig -> UseWorkbench))
  1920.         Config -> ScreenConfig -> SplitStatus = FALSE;
  1921.  
  1922.     if(Config -> ScreenConfig -> UseWorkbench || Config -> ScreenConfig -> ShareScreen)
  1923.     {
  1924.         STRPTR ScreenName = NULL;
  1925.  
  1926.         if(Config -> ScreenConfig -> PubScreenName[0])
  1927.         {
  1928.             struct Screen *SomeScreen;
  1929.  
  1930.             if(SomeScreen = LockPubScreen(Config -> ScreenConfig -> PubScreenName))
  1931.             {
  1932.                 UnlockPubScreen(NULL,SomeScreen);
  1933.  
  1934.                 ScreenName = Config -> ScreenConfig -> PubScreenName;
  1935.             }
  1936.         }
  1937.  
  1938.         if(!(DefaultPubScreen = LockPubScreen(ScreenName)))
  1939.             return(LocaleString(MSG_TERMINIT_FAILED_TO_GET_DEFAULT_PUBLIC_SCREEN_TXT));
  1940.         else
  1941.         {
  1942.             GetDPI(GetVPModeID(&DefaultPubScreen -> ViewPort),&X_DPI,&Y_DPI);
  1943.  
  1944.             strcpy(UserFontName,DefaultPubScreen -> Font -> ta_Name);
  1945.  
  1946.             UserFont . tta_Name    = UserFontName;
  1947.             UserFont . tta_YSize    = DefaultPubScreen -> Font -> ta_YSize;
  1948.             UserFont . tta_Style    = DefaultPubScreen -> Font -> ta_Style;
  1949.             UserFont . tta_Flags    = DefaultPubScreen -> Font -> ta_Flags;
  1950.         }
  1951.     }
  1952.  
  1953.     if(!Config -> ScreenConfig -> UseWorkbench)
  1954.     {
  1955.         GetDPI(Config -> ScreenConfig -> DisplayMode,&X_DPI,&Y_DPI);
  1956.  
  1957.         strcpy(UserFontName,Config -> ScreenConfig -> FontName);
  1958.  
  1959.         UserFont . tta_Name    = UserFontName;
  1960.         UserFont . tta_YSize    = Config -> ScreenConfig -> FontHeight;
  1961.         UserFont . tta_Style    = FS_NORMAL | FSF_TAGGED;
  1962.         UserFont . tta_Flags    = FPF_DESIGNED;
  1963.         UserFont . tta_Tags    = TagDPI;
  1964.  
  1965.         TagDPI[0] . ti_Tag     = TA_DeviceDPI;
  1966.         TagDPI[0] . ti_Data     = (X_DPI << 16) | Y_DPI;
  1967.         TagDPI[1] . ti_Tag     = TAG_DONE;
  1968.     }
  1969.  
  1970.     if(!(UserTextFont = OpenDiskFont(&UserFont)))
  1971.     {
  1972.         if(Config -> ScreenConfig -> UseWorkbench)
  1973.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_FONT_TXT));
  1974.         else
  1975.         {
  1976.             strcpy(Config -> ScreenConfig -> FontName,    "topaz.font");
  1977.             strcpy(UserFontName,                "topaz.font");
  1978.  
  1979.             Config -> ScreenConfig -> FontHeight = 8;
  1980.  
  1981.             UserFont . tta_YSize    = Config -> ScreenConfig -> FontHeight;
  1982.             UserFont . tta_Style    = FS_NORMAL;
  1983.             UserFont . tta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  1984.  
  1985.             if(!(UserTextFont = OpenFont(&UserFont)))
  1986.                 return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_FONT_TXT));
  1987.         }
  1988.     }
  1989.  
  1990. Reopen:    if(Config -> TerminalConfig -> FontMode != FONT_STANDARD)
  1991.     {
  1992.         strcpy(TextFontName,Config -> TerminalConfig -> IBMFontName);
  1993.  
  1994.         TextAttr . tta_YSize = Config -> TerminalConfig -> IBMFontHeight;
  1995.     }
  1996.     else
  1997.     {
  1998.         strcpy(TextFontName,Config -> TerminalConfig -> TextFontName);
  1999.  
  2000.         TextAttr . tta_YSize = Config -> TerminalConfig -> TextFontHeight;
  2001.     }
  2002.  
  2003.     TextAttr . tta_Name    = TextFontName;
  2004.     TextAttr . tta_Style    = FS_NORMAL | FSF_TAGGED;
  2005.     TextAttr . tta_Flags    = FPF_DESIGNED;
  2006.     TextAttr . tta_Tags    = TagDPI;
  2007.  
  2008.     if(!(TextFont = OpenDiskFont(&TextAttr)))
  2009.     {
  2010.         if(Config -> TerminalConfig -> FontMode != FONT_STANDARD)
  2011.         {
  2012.             Config -> TerminalConfig -> FontMode = FONT_STANDARD;
  2013.  
  2014.             goto Reopen;
  2015.         }
  2016.  
  2017.         strcpy(Config -> TerminalConfig -> TextFontName,    "topaz.font");
  2018.         strcpy(TextFontName,                    "topaz.font");
  2019.  
  2020.         Config -> TerminalConfig -> TextFontHeight = 8;
  2021.  
  2022.         TextAttr . tta_YSize    = Config -> TerminalConfig -> TextFontHeight;
  2023.         TextAttr . tta_Style    = FS_NORMAL;
  2024.         TextAttr . tta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  2025.         TextAttr . tta_Tags    = NULL;
  2026.  
  2027.         if(!(TextFont = OpenFont(&TextAttr)))
  2028.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_TEXT_TXT));
  2029.     }
  2030.  
  2031.     TextFontHeight    = TextFont -> tf_YSize;
  2032.     TextFontWidth    = TextFont -> tf_XSize;
  2033.     TextFontBase    = TextFont -> tf_Baseline;
  2034.  
  2035.         /* Determine extra font box width for slanted/boldface glyphs. */
  2036.  
  2037.     FontRightExtend    = MAX(TextFont -> tf_XSize / 2,TextFont -> tf_BoldSmear);
  2038.  
  2039.     CurrentFont = TextFont;
  2040.  
  2041.     GFXFont . ta_YSize = TextFontHeight;
  2042.  
  2043.     if(GFX = (struct TextFont *)OpenDiskFont(&GFXFont))
  2044.     {
  2045.         if(GFX -> tf_XSize != TextFont -> tf_XSize || GFX -> tf_YSize != TextFont -> tf_YSize)
  2046.         {
  2047.             CloseFont(GFX);
  2048.  
  2049.             GFX = NULL;
  2050.         }
  2051.     }
  2052.  
  2053.     UserFontHeight    = UserTextFont -> tf_YSize;
  2054.     UserFontWidth    = UserTextFont -> tf_XSize;
  2055.     UserFontBase    = UserTextFont -> tf_Baseline;
  2056.  
  2057.     if(Config -> ScreenConfig -> UseWorkbench || Config -> ScreenConfig -> ShareScreen)
  2058.     {
  2059.         struct TagItem     SomeTags[7];
  2060.         LONG         FullWidth,
  2061.                  Height,Width,
  2062.                  Index = 0;
  2063.         struct Screen    *LocalScreen = DefaultPubScreen;
  2064.  
  2065.         if(Config -> ScreenConfig -> ShareScreen && !Config -> ScreenConfig -> UseWorkbench)
  2066.         {
  2067.             struct DimensionInfo DimensionInfo;
  2068.  
  2069.             if(ModeNotAvailable(Config -> ScreenConfig -> DisplayMode))
  2070.             {
  2071.                 Config -> ScreenConfig -> DisplayMode = GetVPModeID(&DefaultPubScreen -> ViewPort);
  2072.  
  2073.                 if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2074.                 {
  2075.                     LONG    Width    = DimensionInfo . TxtOScan . MaxX - DimensionInfo . TxtOScan . MinX + 1,
  2076.                         Height    = DimensionInfo . TxtOScan . MaxY - DimensionInfo . TxtOScan . MinY + 1;
  2077.  
  2078.                     if(Width != Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayWidth)
  2079.                         Config -> ScreenConfig -> DisplayWidth = Width;
  2080.  
  2081.                     if(Height != Config -> ScreenConfig -> DisplayHeight && Config -> ScreenConfig -> DisplayHeight)
  2082.                         Config -> ScreenConfig -> DisplayHeight = Height;
  2083.                 }
  2084.             }
  2085.  
  2086.             if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2087.             {
  2088.                 LONG    Depth,ScreenWidth,ScreenHeight;
  2089.                 UWORD    Pens = (UWORD)~0;
  2090.  
  2091.                 if(Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayHeight && AslBase -> lib_Version >= 38)
  2092.                 {
  2093.                     ScreenWidth    = Config -> ScreenConfig -> DisplayWidth;
  2094.                     ScreenHeight    = Config -> ScreenConfig -> DisplayHeight;
  2095.                 }
  2096.                 else
  2097.                 {
  2098.                     ScreenWidth    = 0;
  2099.                     ScreenHeight    = 0;
  2100.                 }
  2101.  
  2102.                 switch(Config -> ScreenConfig -> ColourMode)
  2103.                 {
  2104.                     case COLOUR_EIGHT:
  2105.  
  2106.                         Depth = 3;
  2107.                         break;
  2108.  
  2109.                     case COLOUR_SIXTEEN:
  2110.  
  2111.                         Depth = 4;
  2112.                         break;
  2113.  
  2114.                     case COLOUR_AMIGA:
  2115.  
  2116.                         Depth = 2;
  2117.                         break;
  2118.  
  2119.                     default:
  2120.  
  2121.                         Depth = 1;
  2122.                         break;
  2123.                 }
  2124.  
  2125.                 if(Depth > DimensionInfo . MaxDepth)
  2126.                     Depth = DimensionInfo . MaxDepth;
  2127.  
  2128.                 if(!Kick30 && Depth > 2)
  2129.                     Depth = 2;
  2130.  
  2131.                 if(Config -> ScreenConfig -> Depth && Config -> ScreenConfig -> Depth <= DimensionInfo . MaxDepth)
  2132.                     Depth = Config -> ScreenConfig -> Depth;
  2133.  
  2134. #if defined(_M68030)
  2135.                 SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'030 ",TermDate,TermIDString);
  2136. #endif
  2137.  
  2138. #if defined(_M68040)
  2139.                 SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'040 ",TermDate,TermIDString);
  2140. #endif
  2141.  
  2142. #if !defined(_M68030) && !defined(_M68040)
  2143.                 SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"",TermDate,TermIDString);
  2144. #endif    /* _M68030 */
  2145.  
  2146.                 StatusSizeSetup(NULL,&StatusWidth,&StatusHeight);
  2147.  
  2148.                 if(StatusHeight && StatusWidth > ScreenWidth)
  2149.                     ScreenWidth = StatusWidth;
  2150.  
  2151.                 if(SharedScreen = OpenScreenTags(NULL,
  2152.                     ScreenWidth  ? SA_Width  : TAG_IGNORE,    ScreenWidth,
  2153.                     ScreenHeight ? SA_Height : TAG_IGNORE,    ScreenHeight,
  2154.  
  2155.                     SA_Title,    ScreenTitle,
  2156.                     SA_Depth,    Depth,
  2157.                     SA_Pens,    &Pens,
  2158.                     SA_Overscan,    AslBase -> lib_Version >= 38 ? Config -> ScreenConfig -> OverscanType : OSCAN_TEXT,
  2159.                     SA_DisplayID,    Config -> ScreenConfig -> DisplayMode,
  2160.                     SA_Font,    &UserFont,
  2161.                     SA_AutoScroll,    TRUE,
  2162.                     SA_ShowTitle,    Config -> ScreenConfig -> TitleBar,
  2163.                     SA_PubName,    TermIDString,
  2164.                     SA_Interleaved,    Config -> ScreenConfig -> FasterLayout,
  2165.                     SA_SharePens,    TRUE,
  2166.                 TAG_DONE))
  2167.                 {
  2168.                     LocalScreen = SharedScreen;
  2169.  
  2170.                     if(DefaultPubScreen)
  2171.                     {
  2172.                         UnlockPubScreen(NULL,DefaultPubScreen);
  2173.  
  2174.                         DefaultPubScreen = NULL;
  2175.                     }
  2176.  
  2177.                     if(Config -> ScreenConfig -> MakeScreenPublic)
  2178.                         PubScreenStatus(LocalScreen,NULL);
  2179.                     else
  2180.                         PubScreenStatus(LocalScreen,PSNF_PRIVATE);
  2181.                 }
  2182.             }
  2183.         }
  2184.  
  2185.         if(!SharedScreen)
  2186.         {
  2187. #if defined(_M68030)
  2188.             SPrintf(ScreenTitle,"%s '030 (%s)",TermName,TermDate);
  2189. #endif
  2190.  
  2191. #if defined(_M68040)
  2192.             SPrintf(ScreenTitle,"%s '040 (%s)",TermName,TermDate);
  2193. #endif
  2194.  
  2195. #if !defined(_M68030) && !defined(_M68040)
  2196.             SPrintf(ScreenTitle,"%s (%s)",TermName,TermDate);
  2197. #endif
  2198.         }
  2199.  
  2200.         StatusSizeSetup(LocalScreen,&StatusWidth,&StatusHeight);
  2201.  
  2202.         if(GetBitMapDepth(LocalScreen -> RastPort . BitMap) == 1 || Config -> ScreenConfig -> FasterLayout)
  2203.             UseMasking = FALSE;
  2204.         else
  2205.         {
  2206.             if(Kick30)
  2207.             {
  2208.                 if(GetBitMapAttr(LocalScreen -> RastPort . BitMap,BMA_FLAGS) & BMF_INTERLEAVED)
  2209.                     UseMasking = FALSE;
  2210.                 else
  2211.                     UseMasking = TRUE;
  2212.             }
  2213.             else
  2214.                 UseMasking = TRUE;
  2215.         }
  2216.  
  2217.         VPort = &LocalScreen -> ViewPort;
  2218.  
  2219.             /* Get the current display dimensions. */
  2220.  
  2221.         if(VPort -> ColorMap -> cm_vpe)
  2222.         {
  2223.             struct ViewPortExtra *Extra;
  2224.  
  2225.             Extra = VPort -> ColorMap -> cm_vpe;
  2226.  
  2227.             ScreenWidth    = Extra -> DisplayClip . MaxX - Extra -> DisplayClip . MinX + 1;
  2228.             ScreenHeight    = Extra -> DisplayClip . MaxY - Extra -> DisplayClip . MinY + 1;
  2229.         }
  2230.         else
  2231.         {
  2232.             struct ViewPortExtra *Extra;
  2233.  
  2234.             if(Extra = (struct ViewPortExtra *)GfxLookUp(VPort))
  2235.             {
  2236.                 ScreenWidth    = Extra -> DisplayClip . MaxX - Extra -> DisplayClip . MinX + 1;
  2237.                 ScreenHeight    = Extra -> DisplayClip . MaxY - Extra -> DisplayClip . MinY + 1;
  2238.             }
  2239.             else
  2240.             {
  2241.                 ScreenWidth    = LocalScreen -> Width;
  2242.                 ScreenHeight    = LocalScreen -> Height;
  2243.             }
  2244.         }
  2245.  
  2246.         DepthMask = (1L << GetBitMapDepth(LocalScreen -> RastPort . BitMap)) - 1;
  2247.  
  2248.         switch(Config -> ScreenConfig -> ColourMode)
  2249.         {
  2250.             case COLOUR_SIXTEEN:
  2251.  
  2252.                 if(DepthMask < 15)
  2253.                 {
  2254.                     if(DepthMask >= 7)
  2255.                         Config -> ScreenConfig -> ColourMode = COLOUR_EIGHT;
  2256.                     else
  2257.                     {
  2258.                         if(DepthMask >= 3)
  2259.                             Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2260.                         else
  2261.                             Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2262.                     }
  2263.                 }
  2264.  
  2265.                 break;
  2266.  
  2267.             case COLOUR_EIGHT:
  2268.  
  2269.                 if(DepthMask < 7)
  2270.                 {
  2271.                     if(DepthMask >= 3)
  2272.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2273.                     else
  2274.                         Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2275.                 }
  2276.  
  2277.                 break;
  2278.  
  2279.             case COLOUR_AMIGA:
  2280.  
  2281.                 if(DepthMask < 3)
  2282.                     Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2283.  
  2284.                 break;
  2285.         }
  2286.  
  2287.         if(!(DrawInfo = GetScreenDrawInfo(LocalScreen)))
  2288.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_SCREEN_DRAWINFO_TXT));
  2289.  
  2290.         CreateMenuGlyphs(LocalScreen,DrawInfo,&AmigaGlyph,&CheckGlyph);
  2291.  
  2292.         SZ_SizeSetup(LocalScreen,&UserFont);
  2293.  
  2294.             /* Obtain visual info (whatever that may be). */
  2295.  
  2296.         if(!(VisualInfo = GetVisualInfo(LocalScreen,TAG_DONE)))
  2297.         {
  2298.                 /* Delete the DrawInfo now, or it won't
  2299.                  * get freed during shutdown.
  2300.                  */
  2301.  
  2302.             FreeScreenDrawInfo(LocalScreen,DrawInfo);
  2303.  
  2304.             DrawInfo = NULL;
  2305.  
  2306.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_VISUAL_INFO_TXT));
  2307.         }
  2308.  
  2309.         if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && !Config -> ScreenConfig -> SplitStatus)
  2310.             FullWidth = StatusWidth;
  2311.         else
  2312.             FullWidth = 0;
  2313.  
  2314.         if(WindowBox . Left != -1)
  2315.         {
  2316.             SomeTags[Index  ] . ti_Tag    = WA_Left;
  2317.             SomeTags[Index++] . ti_Data    = WindowBox . Left;
  2318.             SomeTags[Index  ] . ti_Tag    = WA_Top;
  2319.             SomeTags[Index++] . ti_Data    = WindowBox . Top;
  2320.  
  2321.             SomeTags[Index  ] . ti_Tag    = WA_Width;
  2322.             SomeTags[Index++] . ti_Data    = WindowBox . Width;
  2323.             SomeTags[Index  ] . ti_Tag    = WA_Height;
  2324.             SomeTags[Index++] . ti_Data    = WindowBox . Height;
  2325.  
  2326.             WindowBox . Left = -1;
  2327.         }
  2328.         else
  2329.         {
  2330.             LONG WindowLeft = -1,WindowTop = -1,DummyWidth,DummyHeight;
  2331.  
  2332.             GetWindowInfo(WINDOW_MAIN,&WindowLeft,&WindowTop,&DummyWidth,&DummyHeight,0,0);
  2333.  
  2334.             if(Config -> TerminalConfig -> NumColumns < 20)
  2335.             {
  2336.                 LONG Width = GetScreenWidth(NULL);
  2337.  
  2338.                 if(FullWidth && Width < FullWidth)
  2339.                 {
  2340.                     SomeTags[Index  ] . ti_Tag    = WA_InnerWidth;
  2341.                     SomeTags[Index++] . ti_Data    = FullWidth;
  2342.                 }
  2343.                 else
  2344.                 {
  2345.                     SomeTags[Index  ] . ti_Tag    = WA_Width;
  2346.                     SomeTags[Index++] . ti_Data    = Width;
  2347.                 }
  2348.             }
  2349.             else
  2350.             {
  2351.                 SomeTags[Index  ] . ti_Tag    = WA_InnerWidth;
  2352.                 SomeTags[Index++] . ti_Data    = Config -> TerminalConfig -> NumColumns * TextFontWidth;
  2353.             }
  2354.  
  2355.             if(Config -> TerminalConfig -> NumLines < 20)
  2356.             {
  2357.                 SomeTags[Index  ] . ti_Tag    = WA_Height;
  2358.                 SomeTags[Index++] . ti_Data    = GetScreenHeight(NULL) - (LocalScreen -> BarHeight + 1);
  2359.             }
  2360.             else
  2361.             {
  2362.                 SomeTags[Index  ] . ti_Tag    = WA_InnerHeight;
  2363.                 SomeTags[Index++] . ti_Data    = Config -> TerminalConfig -> NumLines * TextFontHeight + StatusHeight;
  2364.             }
  2365.  
  2366.             if(WindowLeft != -1)
  2367.             {
  2368.                 SomeTags[Index  ] . ti_Tag    = WA_Left;
  2369.                 SomeTags[Index++] . ti_Data    = WindowLeft;
  2370.             }
  2371.             else
  2372.             {
  2373.                 SomeTags[Index  ] . ti_Tag    = WA_Left;
  2374.                 SomeTags[Index++] . ti_Data    = GetScreenLeft(NULL);
  2375.             }
  2376.  
  2377.             if(WindowTop != -1)
  2378.             {
  2379.                 SomeTags[Index  ] . ti_Tag    = WA_Top;
  2380.                 SomeTags[Index++] . ti_Data    = WindowTop;
  2381.             }
  2382.         }
  2383.  
  2384.         SomeTags[Index] . ti_Tag = TAG_DONE;
  2385.  
  2386.             /* Open the main window. */
  2387.  
  2388.         if(!(Window = OpenWindowTags(NULL,
  2389.             WA_MaxHeight,        LocalScreen -> Height,
  2390.             WA_MaxWidth,        LocalScreen -> Width,
  2391.             WA_SmartRefresh,    TRUE,
  2392.             WA_CustomScreen,    LocalScreen,
  2393.             WA_NewLookMenus,    TRUE,
  2394.             WA_RMBTrap,        TRUE,
  2395.             WA_IDCMP,        IDCMP_RAWKEY | IDCMP_INACTIVEWINDOW | IDCMP_ACTIVEWINDOW | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | IDCMP_IDCMPUPDATE | IDCMP_MENUHELP,
  2396.             WA_DragBar,        TRUE,
  2397.             WA_DepthGadget,        TRUE,
  2398.             WA_CloseGadget,        TRUE,
  2399.             WA_SizeGadget,        TRUE,
  2400.             WA_SizeBBottom,        Config -> ScreenConfig -> StatusLine == STATUSLINE_DISABLED || Config -> ScreenConfig -> SplitStatus,
  2401.             WA_NoCareRefresh,    TRUE,
  2402.             WA_Title,        ScreenTitle,
  2403.             WA_MenuHelp,        TRUE,
  2404.  
  2405.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  2406.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  2407.  
  2408.             TAG_MORE,        SomeTags,
  2409.         TAG_DONE)))
  2410.         {
  2411.                 /* Delete the DrawInfo now, or it won't
  2412.                  * get freed during shutdown.
  2413.                  */
  2414.  
  2415.             FreeScreenDrawInfo(LocalScreen,DrawInfo);
  2416.  
  2417.             DrawInfo = NULL;
  2418.  
  2419.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  2420.         }
  2421.  
  2422.         if(StatusHeight)
  2423.         {
  2424.             StatusDisplayHeight = StatusHeight;
  2425.  
  2426.             CopyMem(Window -> RPort,StatusRPort = &StatusRastPort,sizeof(struct RastPort));
  2427.  
  2428.             StatusRPort -> BitMap = Window -> RPort -> BitMap;
  2429.         }
  2430.         else
  2431.             StatusRPort = NULL;
  2432.  
  2433.             /* Create a user clip region to keep text from
  2434.              * leaking into the window borders.
  2435.              */
  2436.  
  2437.         if(!(ClipRegion = NewRegion()))
  2438.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  2439.         else
  2440.         {
  2441.             struct Rectangle RegionRectangle;
  2442.  
  2443.                 /* Adjust the region to match the inner window area. */
  2444.  
  2445.             RegionRectangle . MinX = Window -> BorderLeft;
  2446.             RegionRectangle . MinY = Window -> BorderTop;
  2447.             RegionRectangle . MaxX = Window -> Width - (Window -> BorderRight + 1);
  2448.             RegionRectangle . MaxY = Window -> Height - (Window -> BorderBottom + 1);
  2449.  
  2450.                 /* Establish the region. */
  2451.  
  2452.             OrRectRegion(ClipRegion,&RegionRectangle);
  2453.  
  2454.                 /* Install the region. */
  2455.  
  2456.             OldRegion = InstallClipRegion(Window -> WLayer,ClipRegion);
  2457.         }
  2458.  
  2459.         if(FullWidth < 40 * TextFontWidth)
  2460.             FullWidth = 40 * TextFontWidth;
  2461.  
  2462.         Width    = Window -> BorderLeft + FullWidth + Window -> BorderRight;
  2463.         Height    = Window -> BorderTop + 20 * TextFontHeight + Window -> BorderBottom + StatusHeight;
  2464.  
  2465.         if(ChatMode && !(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0]))
  2466.             Height += UserFontHeight + 2;
  2467.  
  2468.         WindowLimits(Window,Width,Height,0,0);
  2469.  
  2470.         if(WorkbenchBase)
  2471.         {
  2472.             if(WorkbenchPort = CreateMsgPort())
  2473.             {
  2474.                 if(!(WorkbenchWindow = AddAppWindow(0,0,Window,WorkbenchPort,TAG_DONE)))
  2475.                 {
  2476.                     DeleteMsgPort(WorkbenchPort);
  2477.  
  2478.                     WorkbenchPort = NULL;
  2479.                 }
  2480.             }
  2481.         }
  2482.     }
  2483.     else
  2484.     {
  2485.         struct DimensionInfo    DimensionInfo;
  2486.         WORD            MaxDepth,
  2487.                     ScreenDepth;
  2488.  
  2489.         if(ModeNotAvailable(Config -> ScreenConfig -> DisplayMode))
  2490.         {
  2491.             struct Screen *PubScreen;
  2492.  
  2493.             if(PubScreen = LockPubScreen(NULL))
  2494.             {
  2495.                 Config -> ScreenConfig -> DisplayMode = GetVPModeID(&PubScreen -> ViewPort);
  2496.  
  2497.                 if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2498.                 {
  2499.                     LONG    Width    = DimensionInfo . TxtOScan . MaxX - DimensionInfo . TxtOScan . MinX + 1,
  2500.                         Height    = DimensionInfo . TxtOScan . MaxY - DimensionInfo . TxtOScan . MinY + 1;
  2501.  
  2502.                     if(Width != Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayWidth)
  2503.                         Config -> ScreenConfig -> DisplayWidth = Width;
  2504.  
  2505.                     if(Height != Config -> ScreenConfig -> DisplayHeight && Config -> ScreenConfig -> DisplayHeight)
  2506.                         Config -> ScreenConfig -> DisplayHeight = Height;
  2507.                 }
  2508.  
  2509.                 UnlockPubScreen(NULL,PubScreen);
  2510.             }
  2511.         }
  2512.  
  2513.         if(!QueryOverscan(Config -> ScreenConfig -> DisplayMode,&DisplayClip,Config -> ScreenConfig -> OverscanType))
  2514.         {
  2515.             OpenFailed = TRUE;
  2516.  
  2517.             ErrorCode = ModeNotAvailable(Config -> ScreenConfig -> DisplayMode);
  2518.  
  2519.             goto OpenS;
  2520.         }
  2521.  
  2522.         if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2523.         {
  2524.             UWORD    MaxWidth,
  2525.                 MaxHeight,
  2526.                 Width,
  2527.                 Height;
  2528.  
  2529.             MaxWidth    = DisplayClip . MaxX - DisplayClip . MinX + 1;
  2530.             MaxHeight    = DisplayClip . MaxY - DisplayClip . MinY + 1;
  2531.  
  2532.             if(Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayHeight && AslBase -> lib_Version >= 38)
  2533.             {
  2534.                 ScreenWidth    = Config -> ScreenConfig -> DisplayWidth;
  2535.                 ScreenHeight    = Config -> ScreenConfig -> DisplayHeight;
  2536.             }
  2537.             else
  2538.             {
  2539.                 ScreenWidth    = MaxWidth;
  2540.                 ScreenHeight    = MaxHeight;
  2541.             }
  2542.  
  2543.             if(Config -> TerminalConfig -> NumColumns < 20)
  2544.                 Width = MaxWidth = ScreenWidth;
  2545.             else
  2546.             {
  2547.                 Width = TextFontWidth * Config -> TerminalConfig -> NumColumns;
  2548.  
  2549.                 ScreenWidth = 0;
  2550.             }
  2551.  
  2552.             if(Config -> TerminalConfig -> NumLines < 20)
  2553.                 Height = MaxHeight = ScreenHeight;
  2554.             else
  2555.             {
  2556.                 Height = TextFontHeight * Config -> TerminalConfig -> NumLines;
  2557.  
  2558.                 if(Config -> ScreenConfig -> TitleBar)
  2559.                     Height += UserFontHeight + 3;
  2560.  
  2561.                 if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED)
  2562.                 {
  2563.                     if(Config -> ScreenConfig -> StatusLine == STATUSLINE_COMPRESSED)
  2564.                         Height += UserFontHeight;
  2565.                     else
  2566.                         Height += 4 + (2 + 2 * UserFontHeight + 2);
  2567.                 }
  2568.  
  2569.                 ScreenHeight = 0;
  2570.             }
  2571.  
  2572.             if(Height > MaxHeight)
  2573.                 Height = MaxHeight;
  2574.  
  2575.             if(Width > MaxWidth)
  2576.                 Width = MaxWidth;
  2577.  
  2578.             if(DimensionInfo . MinRasterWidth <= Width && Width <= DimensionInfo . MaxRasterWidth && Width < MaxWidth)
  2579.             {
  2580.                 UWORD Half;
  2581.  
  2582.                 Width = MaxWidth - Width;
  2583.  
  2584.                 Half = Width / 2;
  2585.  
  2586.                 DisplayClip . MinX += Half;
  2587.                 DisplayClip . MaxX -= Width - Half;
  2588.             }
  2589.  
  2590.             if(DimensionInfo . MinRasterHeight <= Height && Height <= DimensionInfo . MaxRasterHeight)
  2591.                 DisplayClip . MaxY = DisplayClip . MinY + Height - 1;
  2592.  
  2593.             if(!ScreenWidth)
  2594.                 ScreenWidth = DisplayClip . MaxX - DisplayClip . MinX + 1;
  2595.  
  2596.             if(!ScreenHeight)
  2597.                 ScreenHeight = DisplayClip . MaxY - DisplayClip . MinY + 1;
  2598.  
  2599.             MaxDepth = DimensionInfo . MaxDepth;
  2600.         }
  2601.         else
  2602.         {
  2603.             ScreenWidth = ScreenHeight = 0;
  2604.             MaxDepth = 4;
  2605.         }
  2606.  
  2607.             /* We'll configure the screen parameters at
  2608.              * run time, at first we'll set up the screen
  2609.              * depth.
  2610.              */
  2611.  
  2612. PenReset:    if(!Config -> ScreenConfig -> UsePens && Kick30)
  2613.         {
  2614.             for(i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  2615.                 PenArray[i] = Config -> ScreenConfig -> PenArray[i];
  2616.  
  2617.             PenArray[i] = (UWORD)~0;
  2618.         }
  2619.         else
  2620.         {
  2621.             UWORD *Data;
  2622.  
  2623.             switch(Config -> ScreenConfig -> ColourMode)
  2624.             {
  2625.                 case COLOUR_EIGHT:
  2626.  
  2627.                     Data = ANSIPens;
  2628.                     break;
  2629.  
  2630.                 case COLOUR_SIXTEEN:
  2631.  
  2632.                     if(IntuitionBase -> LibNode . lib_Version >= 39)
  2633.                         Data = NewEGAPens;
  2634.                     else
  2635.                         Data = EGAPens;
  2636.  
  2637.                     break;
  2638.  
  2639.                 case COLOUR_AMIGA:
  2640.  
  2641.                     Data = StandardPens;
  2642.                     break;
  2643.  
  2644.                 default:
  2645.  
  2646.                     Data = NULL;
  2647.                     break;
  2648.             }
  2649.  
  2650.             if(Data)
  2651.             {
  2652.                 for(i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  2653.                     PenArray[i] = Data[i];
  2654.  
  2655.                 PenArray[i] = (UWORD)~0;
  2656.             }
  2657.         }
  2658.  
  2659.         switch(Config -> ScreenConfig -> ColourMode)
  2660.         {
  2661.             case COLOUR_EIGHT:
  2662.  
  2663.                     // Special screen depth requested?
  2664.  
  2665.                 if(Config -> ScreenConfig -> Depth)
  2666.                 {
  2667.                         // The minimum number of colours required
  2668.  
  2669.                     if(Config -> ScreenConfig -> Blinking)
  2670.                         ScreenDepth = 4;
  2671.                     else
  2672.                         ScreenDepth = 3;
  2673.  
  2674.                         // This is what the user wanted
  2675.  
  2676.                     RealDepth = Config -> ScreenConfig -> Depth;
  2677.  
  2678.                         // Too deep for this display mode?
  2679.  
  2680.                     if(RealDepth > MaxDepth)
  2681.                         RealDepth = MaxDepth;
  2682.  
  2683.                         // Less colours than required?
  2684.  
  2685.                     if(RealDepth < ScreenDepth && ScreenDepth <= MaxDepth)
  2686.                         RealDepth = ScreenDepth;
  2687.  
  2688.                         // Not enough colours to display it?
  2689.  
  2690.                     if(RealDepth < ScreenDepth)
  2691.                     {
  2692.                             // Return to standard mode
  2693.  
  2694.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2695.  
  2696.                         ConfigChanged = TRUE;
  2697.  
  2698.                         goto PenReset;
  2699.                     }
  2700.                 }
  2701.                 else
  2702.                 {
  2703.                         // The minimum number of colours
  2704.  
  2705.                     if(Config -> ScreenConfig -> Blinking)
  2706.                         ScreenDepth = 4;
  2707.                     else
  2708.                         ScreenDepth = 3;
  2709.  
  2710.                         // Too many for this mode?
  2711.  
  2712.                     if(ScreenDepth > MaxDepth)
  2713.                     {
  2714.                             // Return to standard mode
  2715.  
  2716.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2717.  
  2718.                         ConfigChanged = TRUE;
  2719.  
  2720.                         goto PenReset;
  2721.                     }
  2722.  
  2723.                     RealDepth = ScreenDepth;
  2724.                 }
  2725.  
  2726.                 TagArray[Count++] = SA_Pens;
  2727.                 TagArray[Count++] = (LONG)PenArray;
  2728.  
  2729.                 TagArray[Count++] = SA_BlockPen;
  2730.                 TagArray[Count++] = PenArray[SHADOWPEN];
  2731.  
  2732.                 TagArray[Count++] = SA_DetailPen;
  2733.                 TagArray[Count++] = PenArray[BACKGROUNDPEN];
  2734.  
  2735.                 break;
  2736.  
  2737.             case COLOUR_SIXTEEN:
  2738.  
  2739.                 if(Config -> ScreenConfig -> Depth)
  2740.                 {
  2741.                     if(Config -> ScreenConfig -> Blinking && MaxDepth > 4)
  2742.                         ScreenDepth = 5;
  2743.                     else
  2744.                         ScreenDepth = 4;
  2745.  
  2746.                     RealDepth = Config -> ScreenConfig -> Depth;
  2747.  
  2748.                     if(RealDepth > MaxDepth)
  2749.                         RealDepth = MaxDepth;
  2750.  
  2751.                     if(RealDepth < ScreenDepth && ScreenDepth <= MaxDepth)
  2752.                         RealDepth = ScreenDepth;
  2753.  
  2754.                     if(RealDepth < ScreenDepth)
  2755.                     {
  2756.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2757.  
  2758.                         ConfigChanged = TRUE;
  2759.  
  2760.                         goto PenReset;
  2761.                     }
  2762.                 }
  2763.                 else
  2764.                 {
  2765.                     if(Config -> ScreenConfig -> Blinking && MaxDepth > 4)
  2766.                         ScreenDepth = 5;
  2767.                     else
  2768.                         ScreenDepth = 4;
  2769.  
  2770.                     if(ScreenDepth > MaxDepth)
  2771.                     {
  2772.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2773.  
  2774.                         ConfigChanged = TRUE;
  2775.  
  2776.                         goto PenReset;
  2777.                     }
  2778.  
  2779.                     RealDepth = ScreenDepth;
  2780.                 }
  2781.  
  2782.                 TagArray[Count++] = SA_Pens;
  2783.                 TagArray[Count++] = (LONG)PenArray;
  2784.  
  2785.                 TagArray[Count++] = SA_BlockPen;
  2786.                 TagArray[Count++] = PenArray[SHADOWPEN];
  2787.  
  2788.                 TagArray[Count++] = SA_DetailPen;
  2789.                 TagArray[Count++] = PenArray[BACKGROUNDPEN];
  2790.  
  2791.                 break;
  2792.  
  2793.             case COLOUR_MONO:
  2794.  
  2795.                 if(Config -> ScreenConfig -> Depth)
  2796.                     RealDepth = Config -> ScreenConfig -> Depth;
  2797.                 else
  2798.                     RealDepth = 1;
  2799.  
  2800.                 if(RealDepth > MaxDepth)
  2801.                     RealDepth = MaxDepth;
  2802.  
  2803.                 break;
  2804.  
  2805.             case COLOUR_AMIGA:
  2806.  
  2807.                 if(Config -> ScreenConfig -> Depth)
  2808.                     RealDepth = Config -> ScreenConfig -> Depth;
  2809.                 else
  2810.                     RealDepth = 2;
  2811.  
  2812.                 if(RealDepth > MaxDepth)
  2813.                     RealDepth = MaxDepth;
  2814.  
  2815.                 TagArray[Count++] = SA_Pens;
  2816.                 TagArray[Count++] = (LONG)PenArray;
  2817.  
  2818.                 break;
  2819.         }
  2820.  
  2821.             /* Add the depth value. */
  2822.  
  2823.         TagArray[Count++] = SA_Depth;
  2824.         TagArray[Count++] = RealDepth;
  2825.  
  2826.             /* Terminate the tag array. */
  2827.  
  2828.         TagArray[Count] = TAG_END;
  2829.  
  2830.             /* Set the plane mask. */
  2831.  
  2832.         DepthMask = (1L << RealDepth) - 1;
  2833.  
  2834. #if defined(_M68030)
  2835. OpenS:        SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'030 ",TermDate,TermIDString);
  2836. #endif
  2837.  
  2838. #if defined(_M68040)
  2839. OpenS:        SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'040 ",TermDate,TermIDString);
  2840. #endif
  2841.  
  2842. #if !defined(_M68030) && !defined(_M68040)
  2843. OpenS:        SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"",TermDate,TermIDString);
  2844. #endif
  2845.  
  2846.         /* ALWAYS */
  2847.         {
  2848.             BYTE Interleaved;
  2849.  
  2850.             if(Config -> ScreenConfig -> FasterLayout && Kick30 && RealDepth > 1)
  2851.                 Interleaved = TRUE;
  2852.             else
  2853.                 Interleaved = FALSE;
  2854.  
  2855.             StatusSizeSetup(NULL,&StatusWidth,&StatusHeight);
  2856.  
  2857.             if(StatusHeight && StatusWidth > ScreenWidth)
  2858.                 ScreenWidth = StatusWidth;
  2859.  
  2860.             if(Screen = (struct Screen *)OpenScreenTags(NULL,
  2861.                 ScreenWidth  ? SA_Width  : TAG_IGNORE,    ScreenWidth,
  2862.                 ScreenHeight ? SA_Height : TAG_IGNORE,    ScreenHeight,
  2863.  
  2864.                 SA_Title,    ScreenTitle,
  2865.                 SA_Left,    DisplayClip . MinX,
  2866.                 SA_DClip,    &DisplayClip,
  2867.                 SA_DisplayID,    Config -> ScreenConfig -> DisplayMode,
  2868.                 SA_Font,    &UserFont,
  2869.                 SA_Behind,    TRUE,
  2870.                 SA_AutoScroll,    TRUE,
  2871.                 SA_ShowTitle,    Config -> ScreenConfig -> TitleBar,
  2872.                 SA_PubName,    TermIDString,
  2873.                 SA_ErrorCode,    &ErrorCode,
  2874.                 SA_Interleaved,    Interleaved,
  2875.                 SA_BackFill,    &BackfillHook,
  2876.                 TAG_MORE,    TagArray,
  2877.             TAG_END))
  2878.             {
  2879.                 if(RealDepth > 1 && !Config -> ScreenConfig -> FasterLayout)
  2880.                 {
  2881.                     UseMasking = TRUE;
  2882.  
  2883.                     if(Kick30)
  2884.                     {
  2885.                         if(GetBitMapAttr(Screen -> RastPort . BitMap,BMA_FLAGS) & BMF_INTERLEAVED)
  2886.                             UseMasking = FALSE;
  2887.                     }
  2888.                 }
  2889.                 else
  2890.                     UseMasking = FALSE;
  2891.             }
  2892.         }
  2893.  
  2894.             /* We've got an error. */
  2895.  
  2896.         if(!Screen)
  2897.         {
  2898.             if(!OpenFailed)
  2899.             {
  2900.                 struct Screen *PubScreen;
  2901.  
  2902.                 switch(ErrorCode)
  2903.                 {
  2904.                         /* Can't open screen with these display
  2905.                          * modes.
  2906.                          */
  2907.  
  2908.                     case OSERR_NOMONITOR:
  2909.                     case OSERR_NOCHIPS:
  2910.                     case OSERR_UNKNOWNMODE:
  2911.                     case OSERR_NOTAVAILABLE:
  2912.  
  2913.                         if(PubScreen = LockPubScreen(NULL))
  2914.                         {
  2915.                             struct DimensionInfo DimensionInfo;
  2916.  
  2917.                             Config -> ScreenConfig -> DisplayMode = GetVPModeID(&PubScreen -> ViewPort);
  2918.  
  2919.                             if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2920.                             {
  2921.                                 LONG    Width    = DimensionInfo . TxtOScan . MaxX - DimensionInfo . TxtOScan . MinX + 1,
  2922.                                     Height    = DimensionInfo . TxtOScan . MaxY - DimensionInfo . TxtOScan . MinY + 1;
  2923.  
  2924.                                 if(Width != Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayWidth)
  2925.                                     Config -> ScreenConfig -> DisplayWidth = Width;
  2926.  
  2927.                                 if(Height != Config -> ScreenConfig -> DisplayHeight && Config -> ScreenConfig -> DisplayHeight)
  2928.                                     Config -> ScreenConfig -> DisplayHeight = Height;
  2929.                             }
  2930.  
  2931.                             UnlockPubScreen(NULL,PubScreen);
  2932.                         }
  2933.                         else
  2934.                             Config -> ScreenConfig -> DisplayMode = DEFAULT_MONITOR_ID | HIRESLACE_KEY;
  2935.  
  2936.                         OpenFailed = TRUE;
  2937.  
  2938.                         goto OpenS;
  2939.  
  2940.                     case OSERR_PUBNOTUNIQUE:
  2941.  
  2942.                         return(LocaleString(MSG_TERMINIT_SCREEN_ID_ALREADY_IN_USE_TXT));
  2943.                 }
  2944.             }
  2945.  
  2946.                 /* Some different error, probably out of
  2947.                  * memory.
  2948.                  */
  2949.  
  2950.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_SCREEN_TXT));
  2951.         }
  2952.  
  2953.         if(!(DrawInfo = GetScreenDrawInfo(Screen)))
  2954.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_SCREEN_DRAWINFO_TXT));
  2955.  
  2956.         CreateMenuGlyphs(Screen,DrawInfo,&AmigaGlyph,&CheckGlyph);
  2957.  
  2958.         VPort = &Screen -> ViewPort;
  2959.  
  2960.         ScreenWidth    = Screen -> Width;
  2961.         ScreenHeight    = Screen -> Height;
  2962.  
  2963.         StatusSizeSetup(Screen,&StatusWidth,&StatusHeight);
  2964.  
  2965.             /* Obtain visual info (whatever that may be). */
  2966.  
  2967.         if(!(VisualInfo = GetVisualInfo(Screen,TAG_DONE)))
  2968.         {
  2969.                 /* Delete the DrawInfo now, or it won't
  2970.                  * get freed during shutdown.
  2971.                  */
  2972.  
  2973.             FreeScreenDrawInfo(Screen,DrawInfo);
  2974.  
  2975.             DrawInfo = NULL;
  2976.  
  2977.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_VISUAL_INFO_TXT));
  2978.         }
  2979.  
  2980.         if(Config -> ScreenConfig -> TitleBar)
  2981.         {
  2982.             Top = Screen -> BarHeight + 1;
  2983.  
  2984.             Height = Screen -> Height - (Screen -> BarHeight + 1);
  2985.         }
  2986.         else
  2987.         {
  2988.             Top = 0;
  2989.  
  2990.             Height = Screen -> Height;
  2991.         }
  2992.  
  2993.             /* Open the main window. */
  2994.  
  2995.         if(!(Window = OpenWindowTags(NULL,
  2996.             WA_Top,        Top,
  2997.             WA_Left,    0,
  2998.             WA_Width,    Screen -> Width,
  2999.             WA_Height,    Height,
  3000.             WA_Backdrop,    TRUE,
  3001.             WA_Borderless,    TRUE,
  3002.             WA_SmartRefresh,TRUE,
  3003.             WA_CustomScreen,Screen,
  3004.             WA_NewLookMenus,TRUE,
  3005.             WA_RMBTrap,    TRUE,
  3006.             WA_IDCMP,    IDCMP_RAWKEY | IDCMP_INACTIVEWINDOW | IDCMP_ACTIVEWINDOW | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | IDCMP_SIZEVERIFY | IDCMP_IDCMPUPDATE | IDCMP_MENUHELP,
  3007.             WA_MenuHelp,    TRUE,
  3008.  
  3009.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  3010.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  3011.         TAG_DONE)))
  3012.         {
  3013.                 /* Delete the DrawInfo now, or it won't
  3014.                  * get freed during shutdown.
  3015.                  */
  3016.  
  3017.             FreeScreenDrawInfo(Screen,DrawInfo);
  3018.  
  3019.             DrawInfo = NULL;
  3020.  
  3021.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  3022.         }
  3023.  
  3024.         if(StatusHeight)
  3025.         {
  3026.             StatusDisplayHeight = StatusHeight;
  3027.  
  3028.             CopyMem(Window -> RPort,StatusRPort = &StatusRastPort,sizeof(struct RastPort));
  3029.  
  3030.             StatusRPort -> BitMap = Window -> RPort -> BitMap;
  3031.         }
  3032.         else
  3033.             StatusRPort = NULL;
  3034.     }
  3035.  
  3036.         /* Fill the `default' colour with current values. */
  3037.  
  3038.     if(!Config -> ScreenConfig -> UseWorkbench && Initializing && !SharedScreen)
  3039.     {
  3040.         if(Kick30)
  3041.         {
  3042.             ANSIColourTable = CreateColourTable(8,ANSIColours,NULL);
  3043.             EGAColourTable = CreateColourTable(16,EGAColours,NULL);
  3044.  
  3045.             if(DefaultColourTable = CreateColourTable(16,NULL,NULL))
  3046.                 GetRGB32(VPort -> ColorMap,0,16,(ULONG *)&DefaultColourTable -> Entry[0]);
  3047.  
  3048.             MonoColourTable = CreateColourTable(2,AtomicColours,NULL);
  3049.         }
  3050.  
  3051.         for(i = 0 ; i < 16 ; i++)
  3052.             DefaultColours[i] = GetRGB4(VPort -> ColorMap,i);
  3053.  
  3054.         Initializing = FALSE;
  3055.     }
  3056.  
  3057.         /* Load the approriate colours. */
  3058.  
  3059.     if(LoadColours)
  3060.     {
  3061.         Default2CurrentPalette(Config);
  3062.  
  3063.         LoadColours = FALSE;
  3064.     }
  3065.  
  3066.         /* Reset the current colours and the blinking equivalents. */
  3067.  
  3068.     PaletteSetup(Config);
  3069.  
  3070.     if(!Config -> ScreenConfig -> UseWorkbench && !SharedScreen)
  3071.         LoadColourTable(VPort,NormalColourTable,NormalColours,PaletteSize);
  3072.  
  3073.         /* Get the vanilla rendering pens. */
  3074.  
  3075.     RenderPens[0] = DrawInfo -> dri_Pens[BACKGROUNDPEN];
  3076.     RenderPens[1] = DrawInfo -> dri_Pens[TEXTPEN];
  3077.     RenderPens[2] = DrawInfo -> dri_Pens[SHINEPEN];
  3078.     RenderPens[3] = DrawInfo -> dri_Pens[FILLPEN];
  3079.  
  3080.         /* Are we to use the Workbench screen for text output? */
  3081.  
  3082.     if(Config -> ScreenConfig -> UseWorkbench || (SharedScreen && Kick30))
  3083.     {
  3084.         if(Kick30 && (Config -> ScreenConfig -> ColourMode == COLOUR_EIGHT || Config -> ScreenConfig -> ColourMode == COLOUR_SIXTEEN))
  3085.         {
  3086.             ULONG    R,G,B;
  3087.             BYTE    GotAll = TRUE;
  3088.             WORD    NumPens;
  3089.  
  3090.             if(Config -> ScreenConfig -> ColourMode == COLOUR_EIGHT)
  3091.                 NumPens = 8;
  3092.             else
  3093.                 NumPens = 16;
  3094.  
  3095.             for(i = 0 ; i < 16 ; i++)
  3096.                 MappedPens[1][i] = FALSE;
  3097.  
  3098.                 /* Allocate the text rendering pens, note that
  3099.                  * we will use the currently installed palette
  3100.                  * to obtain those pens which match them best.
  3101.                  * The user will be unable to change these
  3102.                  * colours.
  3103.                  */
  3104.  
  3105.             if(NormalColourTable)
  3106.             {
  3107.                 for(i = 0 ; i < NumPens ; i++)
  3108.                 {
  3109.                         /* Try to obtain a matching pen. */
  3110.  
  3111.                     if((MappedPens[0][i] = ObtainBestPen(VPort -> ColorMap,NormalColourTable -> Entry[i] . Red,NormalColourTable -> Entry[i] . Green,NormalColourTable -> Entry[i] . Blue,
  3112.                         OBP_FailIfBad,TRUE,
  3113.                     TAG_DONE)) == -1)
  3114.                     {
  3115.                         MappedPens[1][i] = FALSE;
  3116.  
  3117.                         GotAll = FALSE;
  3118.  
  3119.                         break;
  3120.                     }
  3121.                     else
  3122.                         MappedPens[1][i] = TRUE;
  3123.                 }
  3124.             }
  3125.             else
  3126.             {
  3127.                 for(i = 0 ; i < NumPens ; i++)
  3128.                 {
  3129.                         /* Split the 12 bit colour palette entry. */
  3130.  
  3131.                     R = (NormalColours[i] >> 8) & 0xF;
  3132.                     G = (NormalColours[i] >> 4) & 0xF;
  3133.                     B =  NormalColours[i]       & 0xF;
  3134.  
  3135.                         /* Try to obtain a matching pen. */
  3136.  
  3137.                     if((MappedPens[0][i] = ObtainBestPen(VPort -> ColorMap,SPREAD((R << 4) | R),SPREAD((G << 4) | G),SPREAD((B << 4) | B),
  3138.                         OBP_FailIfBad,TRUE,
  3139.                     TAG_DONE)) == -1)
  3140.                     {
  3141.                         MappedPens[1][i] = FALSE;
  3142.  
  3143.                         GotAll = FALSE;
  3144.  
  3145.                         break;
  3146.                     }
  3147.                     else
  3148.                         MappedPens[1][i] = TRUE;
  3149.                 }
  3150.             }
  3151.  
  3152.                 /* Did we get what we wanted? */
  3153.  
  3154.             if(!GotAll)
  3155.             {
  3156.                     /* Release all the pens we succeeded
  3157.                      * in allocating.
  3158.                      */
  3159.  
  3160.                 for(i = 0 ; i < NumPens ; i++)
  3161.                 {
  3162.                     if(MappedPens[1][i])
  3163.                         ReleasePen(VPort -> ColorMap,MappedPens[0][i]);
  3164.                 }
  3165.  
  3166.                     /* Use the default rendering pens. */
  3167.  
  3168.                 for(i = 0 ; i < 4 ; i++)
  3169.                 {
  3170.                     MappedPens[0][i] = RenderPens[i];
  3171.                     MappedPens[1][i] = FALSE;
  3172.                 }
  3173.  
  3174.                     /* Set the remaining pens to defaults. */
  3175.  
  3176.                 for(i = 4 ; i < NumPens ; i++)
  3177.                 {
  3178.                     MappedPens[0][i] = RenderPens[1];
  3179.                     MappedPens[1][i] = FALSE;
  3180.                 }
  3181.  
  3182.                     /* Can't do anything else. */
  3183.  
  3184.                 Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  3185.             }
  3186.             else
  3187.                 AllocatedPens = TRUE;
  3188.         }
  3189.         else
  3190.         {
  3191.                 /* Use the default rendering pens. */
  3192.  
  3193.             if(Config -> ScreenConfig -> ColourMode == COLOUR_AMIGA)
  3194.             {
  3195.                 for(i = 0 ; i < 4 ; i++)
  3196.                 {
  3197.                     MappedPens[0][i] = RenderPens[i];
  3198.                     MappedPens[1][i] = FALSE;
  3199.                 }
  3200.  
  3201.                     /* Set the remaining pens to defaults. */
  3202.  
  3203.                 for(i = 4 ; i < 16 ; i++)
  3204.                 {
  3205.                     MappedPens[0][i] = RenderPens[1];
  3206.                     MappedPens[1][i] = FALSE;
  3207.                 }
  3208.             }
  3209.             else
  3210.             {
  3211.                 for(i = 0 ; i < 16 ; i++)
  3212.                 {
  3213.                     MappedPens[0][i] = RenderPens[i & 1];
  3214.                     MappedPens[1][i] = FALSE;
  3215.                 }
  3216.             }
  3217.         }
  3218.  
  3219.         for(i = 0 ; i < 16 ; i++)
  3220.         {
  3221.             MappedPens[0][i + 16] = MappedPens[0][i];
  3222.             MappedPens[1][i + 16] = FALSE;
  3223.         }
  3224.     }
  3225.     else
  3226.     {
  3227.             /* Reset the colour translation table. */
  3228.  
  3229.         for(i = 0 ; i < 32 ; i++)
  3230.         {
  3231.             MappedPens[0][i] = i;
  3232.             MappedPens[1][i] = FALSE;
  3233.         }
  3234.     }
  3235.  
  3236.         /* Determine default text rendering colour. */
  3237.  
  3238.     switch(Config -> ScreenConfig -> ColourMode)
  3239.     {
  3240.         case COLOUR_SIXTEEN:
  3241.  
  3242.             SafeTextPen = MappedPens[0][15];
  3243.             break;
  3244.  
  3245.         case COLOUR_EIGHT:
  3246.  
  3247.             SafeTextPen = MappedPens[0][7];
  3248.             break;
  3249.  
  3250.         case COLOUR_AMIGA:
  3251.         case COLOUR_MONO:
  3252.  
  3253.             SafeTextPen = MappedPens[0][1];
  3254.             break;
  3255.     }
  3256.  
  3257.         /* Take care of pen and attribute mapping. */
  3258.  
  3259.     if(Config -> EmulationConfig -> UseStandardPens)
  3260.     {
  3261.         for(i = 0 ; i < 16 ; i++)
  3262.         {
  3263.             PenTable[i]        = i;
  3264.             TextAttributeTable[i]    = i;
  3265.         }
  3266.     }
  3267.     else
  3268.     {
  3269.         UBYTE Value;
  3270.  
  3271.         memcpy(PenTable,Config -> EmulationConfig -> Pens,sizeof(Config -> EmulationConfig -> Pens));
  3272.  
  3273.         for(i = 0 ; i < 16 ; i++)
  3274.         {
  3275.             Value = 0;
  3276.  
  3277.             if(i & ATTR_UNDERLINE)
  3278.             {
  3279.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_UNDERLINE])
  3280.                 {
  3281.                     case TEXTATTR_UNDERLINE:
  3282.  
  3283.                         Value |= ATTR_UNDERLINE;
  3284.                         break;
  3285.  
  3286.                     case TEXTATTR_HIGHLIGHT:
  3287.  
  3288.                         Value |= ATTR_HIGHLIGHT;
  3289.                         break;
  3290.  
  3291.                     case TEXTATTR_BLINK:
  3292.  
  3293.                         Value |= ATTR_BLINK;
  3294.                         break;
  3295.  
  3296.                     case TEXTATTR_INVERSE:
  3297.  
  3298.                         Value |= ATTR_INVERSE;
  3299.                         break;
  3300.                 }
  3301.             }
  3302.  
  3303.             if(i & ATTR_HIGHLIGHT)
  3304.             {
  3305.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_HIGHLIGHT])
  3306.                 {
  3307.                     case TEXTATTR_UNDERLINE:
  3308.  
  3309.                         Value |= ATTR_UNDERLINE;
  3310.                         break;
  3311.  
  3312.                     case TEXTATTR_HIGHLIGHT:
  3313.  
  3314.                         Value |= ATTR_HIGHLIGHT;
  3315.                         break;
  3316.  
  3317.                     case TEXTATTR_BLINK:
  3318.  
  3319.                         Value |= ATTR_BLINK;
  3320.                         break;
  3321.  
  3322.                     case TEXTATTR_INVERSE:
  3323.  
  3324.                         Value |= ATTR_INVERSE;
  3325.                         break;
  3326.                 }
  3327.             }
  3328.  
  3329.             if(i & ATTR_BLINK)
  3330.             {
  3331.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_BLINK])
  3332.                 {
  3333.                     case TEXTATTR_UNDERLINE:
  3334.  
  3335.                         Value |= ATTR_UNDERLINE;
  3336.                         break;
  3337.  
  3338.                     case TEXTATTR_HIGHLIGHT:
  3339.  
  3340.                         Value |= ATTR_HIGHLIGHT;
  3341.                         break;
  3342.  
  3343.                     case TEXTATTR_BLINK:
  3344.  
  3345.                         Value |= ATTR_BLINK;
  3346.                         break;
  3347.  
  3348.                     case TEXTATTR_INVERSE:
  3349.  
  3350.                         Value |= ATTR_INVERSE;
  3351.                         break;
  3352.                 }
  3353.             }
  3354.  
  3355.             if(i & ATTR_INVERSE)
  3356.             {
  3357.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_INVERSE])
  3358.                 {
  3359.                     case TEXTATTR_UNDERLINE:
  3360.  
  3361.                         Value |= ATTR_UNDERLINE;
  3362.                         break;
  3363.  
  3364.                     case TEXTATTR_HIGHLIGHT:
  3365.  
  3366.                         Value |= ATTR_HIGHLIGHT;
  3367.                         break;
  3368.  
  3369.                     case TEXTATTR_BLINK:
  3370.  
  3371.                         Value |= ATTR_BLINK;
  3372.                         break;
  3373.  
  3374.                     case TEXTATTR_INVERSE:
  3375.  
  3376.                         Value |= ATTR_INVERSE;
  3377.                         break;
  3378.                 }
  3379.             }
  3380.  
  3381.             TextAttributeTable[i] = Value;
  3382.         }
  3383.     }
  3384.  
  3385.         /* Determine window inner dimensions and top/left edge offsets. */
  3386.  
  3387.     UpdateTerminalLimits();
  3388.  
  3389.         /* Set up scaling data (bitmaps & rastports). */
  3390.  
  3391.     if(!CreateScale(Window))
  3392.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_FONT_SCALING_INFO_TXT));
  3393.  
  3394.     if(!CreateOffsetTables())
  3395.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_OFFSET_TABLES_TXT));
  3396.  
  3397.     TabStopMax = Window -> WScreen -> Width / TextFontWidth;
  3398.  
  3399.         /* Allocate the tab stop line. */
  3400.  
  3401.     if(!(TabStops = (BYTE *)AllocVecPooled(TabStopMax,MEMF_ANY | MEMF_CLEAR)))
  3402.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  3403.  
  3404.         /* Push it on the window stack (should become bottommost
  3405.          * entry).
  3406.          */
  3407.  
  3408.     PushWindow(Window);
  3409.  
  3410.     if(TermPort)
  3411.         TermPort -> TopWindow = Window;
  3412.  
  3413.     if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && Config -> ScreenConfig -> SplitStatus)
  3414.     {
  3415.         if(!(StatusWindow = OpenWindowTags(NULL,
  3416.             WA_Top,            Window -> TopEdge + Window -> Height,
  3417.             WA_Left,        Window -> LeftEdge,
  3418.             WA_InnerWidth,        StatusWidth,
  3419.             WA_InnerHeight,        StatusHeight,
  3420.             WA_DragBar,        TRUE,
  3421.             WA_DepthGadget,        TRUE,
  3422.             WA_NewLookMenus,    TRUE,
  3423.             WA_Title,        ScreenTitle,
  3424.             WA_CustomScreen,    Window -> WScreen,
  3425.             WA_RMBTrap,        TRUE,
  3426.             WA_CloseGadget,        TRUE,
  3427.             WA_MenuHelp,        TRUE,
  3428.  
  3429.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  3430.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  3431.         TAG_DONE)))
  3432.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_STATUS_WINDOW_TXT));
  3433.     }
  3434.     else
  3435.         StatusWindow = NULL;
  3436.  
  3437.     if(StatusWindow)
  3438.     {
  3439.         StatusWindow -> UserPort = Window -> UserPort;
  3440.  
  3441.         ModifyIDCMP(StatusWindow,Window -> IDCMPFlags);
  3442.     }
  3443.  
  3444.     UpdateTerminalLimits();
  3445.  
  3446.     RPort = Window -> RPort;
  3447.  
  3448.         /* Default console setup. */
  3449.  
  3450.     CursorX = 0;
  3451.     CursorY    = 0;
  3452.  
  3453.     SetDrMd(RPort,JAM2);
  3454.  
  3455.         /* Set the font. */
  3456.  
  3457.     SetFont(RPort,CurrentFont);
  3458.  
  3459.         /* Redirect AmigaDOS requesters. */
  3460.  
  3461.     OldWindowPtr = ThisProcess -> pr_WindowPtr;
  3462.  
  3463.     ThisProcess -> pr_WindowPtr = (APTR)Window;
  3464.  
  3465.         /* Create the character raster. */
  3466.  
  3467.     if(!CreateRaster())
  3468.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_SCREEN_RASTER_TXT));
  3469.  
  3470.     ConOutputUpdate();
  3471.  
  3472.     ConFontScaleUpdate();
  3473.  
  3474.         /* Set up the scrolling info. */
  3475.  
  3476.     ScrollLineCount = Window -> WScreen -> Height / TextFontHeight;
  3477.  
  3478.     if(!(ScrollLines = (struct ScrollLineInfo *)AllocVecPooled(sizeof(struct ScrollLineInfo) * ScrollLineCount,MEMF_ANY|MEMF_CLEAR)))
  3479.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SCROLLING_SUPPORT_INFO_TXT));
  3480.  
  3481.         /* Create the menu strip. */
  3482.  
  3483.     if(Error = BuildMenu())
  3484.         return(Error);
  3485.  
  3486.         /* Disable the `Execute ARexx Command' menu item if
  3487.          * the rexx server is not available.
  3488.          */
  3489.  
  3490.     if(!RexxSysBase)
  3491.         OffItem(MEN_EXECUTE_REXX_COMMAND);
  3492.  
  3493.     if(Recording)
  3494.     {
  3495.         OnItem(MEN_RECORD_LINE);
  3496.  
  3497.         CheckItem(MEN_RECORD,TRUE);
  3498.         CheckItem(MEN_RECORD_LINE,RecordingLine);
  3499.     }
  3500.     else
  3501.     {
  3502.         OffItem(MEN_RECORD_LINE);
  3503.  
  3504.         CheckItem(MEN_RECORD,FALSE);
  3505.         CheckItem(MEN_RECORD_LINE,FALSE);
  3506.     }
  3507.  
  3508.     CheckItem(MEN_DISABLE_TRAPS,!(WatchTraps && GenericListTable[GLIST_TRAP] -> ListHeader . mlh_Head -> mln_Succ));
  3509.  
  3510.     if(StatusWindow)
  3511.     {
  3512.         SetMenuStrip(StatusWindow,Menu);
  3513.  
  3514.         StatusWindow -> Flags &= ~WFLG_RMBTRAP;
  3515.  
  3516.         SetDrMd(StatusWindow -> RPort,JAM2);
  3517.     }
  3518.  
  3519.         /* Add a tick if file capture is active. */
  3520.  
  3521.     if(FileCapture)
  3522.         CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  3523.     else
  3524.         CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  3525.  
  3526.         /* Add a tick if printer capture is active. */
  3527.  
  3528.     CheckItem(MEN_CAPTURE_TO_PRINTER,PrinterCapture != NULL);
  3529.  
  3530.         /* Add a tick if the buffer is frozen. */
  3531.  
  3532.     CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  3533.  
  3534.         /* Disable the dialing functions if online. */
  3535.  
  3536.     ObtainSemaphore(&OnlineSemaphore);
  3537.  
  3538.     if(Online)
  3539.         SetDialMenu(FALSE);
  3540.     else
  3541.         SetDialMenu(TRUE);
  3542.  
  3543.     ReleaseSemaphore(&OnlineSemaphore);
  3544.  
  3545.         /* Take care of the chat line. */
  3546.  
  3547.     if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0])
  3548.         OffItem(MEN_CHAT_LINE);
  3549.     else
  3550.         CheckItem(MEN_CHAT_LINE,ChatMode);
  3551.  
  3552.         /* Update the clipboard menus. */
  3553.  
  3554.     SetClipMenu(FALSE);
  3555.  
  3556.     if(!XProtocolBase)
  3557.         SetTransferMenu(FALSE);
  3558.  
  3559.         /* Disable the `Print Screen' and `Save ASCII' functions
  3560.          * if raster is not enabled.
  3561.          */
  3562.  
  3563.     SetRasterMenu(RasterEnabled);
  3564.  
  3565.         /* Enable the menu. */
  3566.  
  3567.     Window -> Flags &= ~WFLG_RMBTRAP;
  3568.  
  3569.     strcpy(EmulationName,LocaleString(MSG_TERMXEM_NO_EMULATION_TXT));
  3570.  
  3571.         /* Create the status server. */
  3572.  
  3573.     Forbid();
  3574.  
  3575.     if(StatusProcess = CreateNewProcTags(
  3576.         NP_Entry,    StatusServer,
  3577.         NP_Name,    "term Status Process",
  3578.         NP_WindowPtr,    -1,
  3579.         NP_Priority,    5,
  3580.     TAG_DONE))
  3581.     {
  3582.         ClrSignal(SIG_HANDSHAKE);
  3583.  
  3584.         Wait(SIG_HANDSHAKE);
  3585.     }
  3586.  
  3587.     Permit();
  3588.  
  3589.         /* Status server has `died'. */
  3590.  
  3591.     if(!StatusProcess)
  3592.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_STATUS_TASK_TXT));
  3593.  
  3594.         /* Obtain the default public screen name just in case
  3595.          * we'll need it later.
  3596.          */
  3597.  
  3598.     GetDefaultPubScreen(DefaultPubScreenName);
  3599.  
  3600.         /* Set up the window size. */
  3601.  
  3602.     ScreenSizeStuff();
  3603.  
  3604.         /* Select the default console data processing routine. */
  3605.  
  3606.     Forbid();
  3607.  
  3608.     ConProcessData = ConProcessData8;
  3609.  
  3610.     Permit();
  3611.  
  3612.         /* Handle the remaining terminal setup. */
  3613.  
  3614.     if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0])
  3615.     {
  3616.         if(!OpenEmulator(Config -> TerminalConfig -> EmulationFileName))
  3617.         {
  3618.             Config -> TerminalConfig -> EmulationMode = EMULATION_ANSIVT100;
  3619.  
  3620.             ResetDisplay = TRUE;
  3621.  
  3622.             RasterEnabled = TRUE;
  3623.  
  3624.             MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),Config -> TerminalConfig -> EmulationFileName);
  3625.         }
  3626.         else
  3627.         {
  3628.             if(RasterEnabled)
  3629.                 RasterEnabled = FALSE;
  3630.  
  3631.             SetRasterMenu(RasterEnabled);
  3632.         }
  3633.     }
  3634.  
  3635.         /* Choose the right console data processing routine. */
  3636.  
  3637.     ConProcessUpdate();
  3638.  
  3639.         /* Reset terminal emulation. */
  3640.  
  3641.     if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  3642.     {
  3643.         ClearCursor();
  3644.  
  3645.         ForegroundPen = GetPenIndex(SafeTextPen);
  3646.         BackgroundPen = 0;
  3647.  
  3648.         UpdatePens();
  3649.  
  3650.         Reset();
  3651.  
  3652.         DrawCursor();
  3653.     }
  3654.     else
  3655.     {
  3656.         if(XEmulatorBase)
  3657.             XEmulatorResetConsole(XEM_IO);
  3658.     }
  3659.  
  3660.         /* Restart the fast! macro panel. */
  3661.  
  3662.     if(HadFastMacros || Config -> MiscConfig -> OpenFastMacroPanel)
  3663.         OpenFastWindow();
  3664.  
  3665.     if(Config -> TerminalConfig -> UseTerminalTask && Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  3666.         CreateEmulationProcess();
  3667.     else
  3668.         DeleteEmulationProcess();
  3669.  
  3670.     CreateLED();
  3671.  
  3672.     TTYResize();
  3673.  
  3674.     return(NULL);
  3675. }
  3676.  
  3677.     /* CloseAll():
  3678.      *
  3679.      *    Free all resources and leave the program.
  3680.      */
  3681.  
  3682. VOID __regargs
  3683. CloseAll(BYTE CloseDOS)
  3684. {
  3685.     WORD i;
  3686.  
  3687.     Forbid();
  3688.  
  3689.     if(RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Name)
  3690.         RemSemaphore(&RendezvousSemaphore);
  3691.  
  3692.     Permit();
  3693.  
  3694. #ifdef DATAFEED
  3695.     {
  3696.         extern BPTR DataFeed;
  3697.  
  3698.         if(DataFeed)
  3699.         {
  3700.             Close(DataFeed);
  3701.  
  3702.             DataFeed = NULL;
  3703.         }
  3704.     }
  3705. #endif    /* DATAFEED */
  3706.  
  3707.     Forbid();
  3708.  
  3709.     if(DialMsg)
  3710.     {
  3711.         DialMsg -> rm_Result1 = RC_WARN;
  3712.         DialMsg -> rm_Result2 = 0;
  3713.  
  3714.         ReplyMsg(DialMsg);
  3715.  
  3716.         DialMsg = NULL;
  3717.     }
  3718.  
  3719.     Permit();
  3720.  
  3721.     DeleteRecord();
  3722.  
  3723.     DeleteQueueProcess();
  3724.  
  3725.     SoundExit();
  3726.  
  3727.     SZ_SizeCleanup();
  3728.  
  3729.     FreeDialList(TRUE);
  3730.  
  3731.     if(SpecialQueue)
  3732.     {
  3733.         DeleteMsgQueue(SpecialQueue);
  3734.  
  3735.         SpecialQueue = NULL;
  3736.     }
  3737.  
  3738.     if(SpecialTable)
  3739.     {
  3740.         FreeVecPooled(SpecialTable);
  3741.  
  3742.         SpecialTable = NULL;
  3743.     }
  3744.  
  3745.     if(AbortTable)
  3746.     {
  3747.         FreeVecPooled(AbortTable);
  3748.  
  3749.         AbortTable = NULL;
  3750.     }
  3751.  
  3752.     if(BackupConfig)
  3753.     {
  3754.         DeleteConfiguration(BackupConfig);
  3755.  
  3756.         BackupConfig = NULL;
  3757.     }
  3758.  
  3759.     if(IntuitionBase && Window)
  3760.         BlockWindows();
  3761.  
  3762.     /* ALWAYS */
  3763.     {
  3764.         extern struct MsgPort *RexxPort;
  3765.  
  3766.         if(RexxPort)
  3767.             RemPort(RexxPort);
  3768.     }
  3769.  
  3770.     if(EditList)
  3771.     {
  3772.         DeleteList(EditList);
  3773.  
  3774.         EditList = NULL;
  3775.     }
  3776.  
  3777.     if(EditLabels)
  3778.     {
  3779.         FreeVecPooled(EditLabels);
  3780.  
  3781.         EditLabels = NULL;
  3782.     }
  3783.  
  3784.     DeleteChatGadget();
  3785.  
  3786.     if(TermRexxPort)
  3787.     {
  3788.         if(RexxSysBase)
  3789.         {
  3790.             struct Message *Msg;
  3791.  
  3792.             while(Msg = GetMsg(TermRexxPort))
  3793.                 ReplyMsg(Msg);
  3794.         }
  3795.  
  3796.         DeleteMsgPort(TermRexxPort);
  3797.  
  3798.         TermRexxPort = NULL;
  3799.     }
  3800.  
  3801.     if(RexxProcess)
  3802.     {
  3803.         Forbid();
  3804.  
  3805.         Signal(RexxProcess,SIG_KILL);
  3806.  
  3807.         ClrSignal(SIG_HANDSHAKE);
  3808.  
  3809.         Wait(SIG_HANDSHAKE);
  3810.  
  3811.         Permit();
  3812.  
  3813.         RexxProcess = NULL;
  3814.     }
  3815.  
  3816.     if(RexxSysBase)
  3817.     {
  3818.         CloseLibrary(RexxSysBase);
  3819.  
  3820.         RexxSysBase = NULL;
  3821.     }
  3822.  
  3823.     if(XprIO && XProtocolBase)
  3824.         XProtocolCleanup(XprIO);
  3825.  
  3826.     if(XProtocolBase)
  3827.     {
  3828.         CloseLibrary(XProtocolBase);
  3829.  
  3830.         XProtocolBase = NULL;
  3831.     }
  3832.  
  3833.     if(XprIO)
  3834.     {
  3835.         FreeVec(XprIO);
  3836.  
  3837.         XprIO = NULL;
  3838.     }
  3839.  
  3840.     if(CursorKeys)
  3841.     {
  3842.         FreeVecPooled(CursorKeys);
  3843.  
  3844.         CursorKeys = NULL;
  3845.     }
  3846.  
  3847.     if(MacroKeys)
  3848.     {
  3849.         FreeVecPooled(MacroKeys);
  3850.  
  3851.         MacroKeys = NULL;
  3852.     }
  3853.  
  3854.     FreeList(&ARexxQueue);
  3855.  
  3856.     TerminateBuffer();
  3857.  
  3858.     DeleteSpeech();
  3859.  
  3860.     Forbid();
  3861.  
  3862.     BufferClosed = TRUE;
  3863.  
  3864.     DeleteBuffer();
  3865.  
  3866.     Permit();
  3867.  
  3868.     if(AttentionBuffers[0])
  3869.     {
  3870.         FreeVecPooled(AttentionBuffers[0]);
  3871.  
  3872.         AttentionBuffers[0] = NULL;
  3873.     }
  3874.  
  3875.     if(SendTable)
  3876.     {
  3877.         FreeTranslationTable(SendTable);
  3878.  
  3879.         SendTable = NULL;
  3880.     }
  3881.  
  3882.     if(ReceiveTable)
  3883.     {
  3884.         FreeTranslationTable(ReceiveTable);
  3885.  
  3886.         ReceiveTable = NULL;
  3887.     }
  3888.  
  3889.     FreeDialList(TRUE);
  3890.  
  3891.     DeleteOffsetTables();
  3892.  
  3893.     FreeList(&FastMacroList);
  3894.     FreeList((struct List *)&ReviewBufferHistory);
  3895.     FreeList((struct List *)&TextBufferHistory);
  3896.  
  3897.     for(i = GLIST_UPLOAD ; i < GLIST_COUNT ; i++)
  3898.     {
  3899.         if(GenericListTable[i])
  3900.         {
  3901.             DeleteGenericList(GenericListTable[i]);
  3902.  
  3903.             GenericListTable[i] = NULL;
  3904.         }
  3905.     }
  3906.  
  3907.     if(FileCapture)
  3908.     {
  3909.         BufferClose(FileCapture);
  3910.  
  3911.         if(!GetFileSize(CaptureName))
  3912.             DeleteFile(CaptureName);
  3913.         else
  3914.         {
  3915.             AddProtection(CaptureName,FIBF_EXECUTE);
  3916.  
  3917.             if(Config -> MiscConfig -> CreateIcons)
  3918.                 AddIcon(CaptureName,FILETYPE_TEXT,FALSE);
  3919.         }
  3920.  
  3921.         FileCapture = NULL;
  3922.     }
  3923.  
  3924.     if(PrinterCapture)
  3925.     {
  3926.         Close(PrinterCapture);
  3927.  
  3928.         PrinterCapture = NULL;
  3929.     }
  3930.  
  3931.         /* Close the external emulator. */
  3932.  
  3933.     if(XEmulatorBase)
  3934.     {
  3935.         if(XEM_IO)
  3936.         {
  3937.             XEmulatorMacroKeyFilter(XEM_IO,NULL);
  3938.             XEmulatorCloseConsole(XEM_IO);
  3939.             XEmulatorCleanup(XEM_IO);
  3940.  
  3941.             FreeVec(XEM_IO);
  3942.  
  3943.             XEM_IO = NULL;
  3944.         }
  3945.  
  3946.         CloseLibrary(XEmulatorBase);
  3947.  
  3948.         XEmulatorBase = NULL;
  3949.     }
  3950.  
  3951.     if(XEM_MacroKeys)
  3952.     {
  3953.         FreeVecPooled(XEM_MacroKeys);
  3954.  
  3955.         XEM_MacroKeys = NULL;
  3956.     }
  3957.  
  3958.     DeleteDisplay();
  3959.  
  3960.     CaptureParserExit();
  3961.  
  3962.     if(KeySegment)
  3963.     {
  3964.         UnLoadSeg(KeySegment);
  3965.  
  3966.         KeySegment = NULL;
  3967.     }
  3968.  
  3969.     StopCall(TRUE);
  3970.  
  3971.     if(CheckBit != -1)
  3972.     {
  3973.         FreeSignal(CheckBit);
  3974.  
  3975.         CheckBit = -1;
  3976.     }
  3977.  
  3978.     ClearSerial();
  3979.  
  3980.     DeleteSerial();
  3981.  
  3982.     DeletePatternList(PatternList);
  3983.  
  3984.     if(TimeRequest)
  3985.     {
  3986.         if(TimeRequest -> tr_node . io_Device)
  3987.             CloseDevice(TimeRequest);
  3988.  
  3989.         DeleteIORequest(TimeRequest);
  3990.  
  3991.         TimeRequest = NULL;
  3992.     }
  3993.  
  3994.     if(TimePort)
  3995.     {
  3996.         DeleteMsgPort(TimePort);
  3997.  
  3998.         TimePort = NULL;
  3999.     }
  4000.  
  4001.     ShutdownCx();
  4002.  
  4003.     if(NormalColourTable)
  4004.     {
  4005.         DeleteColourTable(NormalColourTable);
  4006.  
  4007.         NormalColourTable = NULL;
  4008.     }
  4009.  
  4010.     if(BlinkColourTable)
  4011.     {
  4012.         DeleteColourTable(BlinkColourTable);
  4013.  
  4014.         BlinkColourTable = NULL;
  4015.     }
  4016.  
  4017.     if(ANSIColourTable)
  4018.     {
  4019.         DeleteColourTable(ANSIColourTable);
  4020.  
  4021.         ANSIColourTable = NULL;
  4022.     }
  4023.  
  4024.     if(EGAColourTable)
  4025.     {
  4026.         DeleteColourTable(EGAColourTable);
  4027.  
  4028.         EGAColourTable = NULL;
  4029.     }
  4030.  
  4031.     if(DefaultColourTable)
  4032.     {
  4033.         DeleteColourTable(DefaultColourTable);
  4034.  
  4035.         DefaultColourTable = NULL;
  4036.     }
  4037.  
  4038.     if(MonoColourTable)
  4039.     {
  4040.         DeleteColourTable(MonoColourTable);
  4041.  
  4042.         MonoColourTable = NULL;
  4043.     }
  4044.  
  4045.     if(TermPort)
  4046.     {
  4047.         if(TermID != -1)
  4048.         {
  4049.             ObtainSemaphore(&TermPort -> OpenSemaphore);
  4050.  
  4051.             TermPort -> OpenCount--;
  4052.  
  4053.             if(TermPort -> OpenCount <= 0 && !TermPort -> HoldIt)
  4054.             {
  4055.                 RemPort(&TermPort -> ExecNode);
  4056.  
  4057.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  4058.  
  4059.                 FreeVec(TermPort);
  4060.             }
  4061.             else
  4062.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  4063.  
  4064.             TermID = -1;
  4065.         }
  4066.  
  4067.         TermPort = NULL;
  4068.     }
  4069.  
  4070.     CloseClip();
  4071.  
  4072. //    DebugExit();
  4073.  
  4074.     if(GTLayoutBase)
  4075.     {
  4076.         CloseLibrary(GTLayoutBase);
  4077.  
  4078.         GTLayoutBase = NULL;
  4079.     }
  4080.  
  4081.     if(Config)
  4082.     {
  4083.         DeleteConfiguration(Config);
  4084.  
  4085.         Config = NULL;
  4086.     }
  4087.  
  4088.     if(PrivateConfig)
  4089.     {
  4090.         DeleteConfiguration(PrivateConfig);
  4091.  
  4092.         PrivateConfig = NULL;
  4093.     }
  4094.  
  4095.     if(FakeInputEvent)
  4096.     {
  4097.         FreeVecPooled(FakeInputEvent);
  4098.  
  4099.         FakeInputEvent = NULL;
  4100.     }
  4101.  
  4102.     if(ConsoleDevice)
  4103.     {
  4104.         CloseDevice(ConsoleRequest);
  4105.  
  4106.         ConsoleDevice = NULL;
  4107.     }
  4108.  
  4109.     if(ConsoleRequest)
  4110.     {
  4111.         FreeVecPooled(ConsoleRequest);
  4112.  
  4113.         ConsoleRequest = NULL;
  4114.     }
  4115.  
  4116.     if(IconBase)
  4117.     {
  4118.         CloseLibrary(IconBase);
  4119.  
  4120.         IconBase = NULL;
  4121.     }
  4122.  
  4123.     if(DataTypesBase)
  4124.     {
  4125.         CloseLibrary(DataTypesBase);
  4126.  
  4127.         DataTypesBase = NULL;
  4128.     }
  4129.  
  4130.     if(WorkbenchBase)
  4131.     {
  4132.         CloseLibrary(WorkbenchBase);
  4133.  
  4134.         WorkbenchBase = NULL;
  4135.     }
  4136.  
  4137.     if(OwnDevUnitBase)
  4138.     {
  4139.         CloseLibrary(OwnDevUnitBase);
  4140.  
  4141.         OwnDevUnitBase = NULL;
  4142.     }
  4143.  
  4144.     if(CxBase)
  4145.     {
  4146.         CloseLibrary(CxBase);
  4147.  
  4148.         CxBase = NULL;
  4149.     }
  4150.  
  4151.     if(IFFParseBase)
  4152.     {
  4153.         CloseLibrary(IFFParseBase);
  4154.  
  4155.         IFFParseBase = NULL;
  4156.     }
  4157.  
  4158.     if(AslBase)
  4159.     {
  4160.         CloseLibrary(AslBase);
  4161.  
  4162.         AslBase = NULL;
  4163.     }
  4164.  
  4165.     if(DiskfontBase)
  4166.     {
  4167.         CloseLibrary(DiskfontBase);
  4168.  
  4169.         DiskfontBase = NULL;
  4170.     }
  4171.  
  4172.     if(GadToolsBase)
  4173.     {
  4174.         CloseLibrary(GadToolsBase);
  4175.  
  4176.         GadToolsBase = NULL;
  4177.     }
  4178.  
  4179.     if(LayersBase)
  4180.     {
  4181.         CloseLibrary(LayersBase);
  4182.  
  4183.         LayersBase = NULL;
  4184.     }
  4185.  
  4186.     if(GfxBase)
  4187.     {
  4188.         CloseLibrary(GfxBase);
  4189.  
  4190.         GfxBase = NULL;
  4191.     }
  4192.  
  4193.     if(IntuitionBase)
  4194.     {
  4195.         CloseLibrary(IntuitionBase);
  4196.  
  4197.         IntuitionBase = NULL;
  4198.     }
  4199.  
  4200.     LocaleClose();
  4201.  
  4202.     if(UtilityBase)
  4203.     {
  4204.         CloseLibrary(UtilityBase);
  4205.  
  4206.         UtilityBase = NULL;
  4207.     }
  4208.  
  4209. #ifdef DEBUG
  4210.     DebugExit();
  4211. #endif    /* DEBUG */
  4212.  
  4213.     MemoryCleanup();
  4214.  
  4215.     if(WBenchMsg)
  4216.     {
  4217.         CurrentDir(WBenchLock);
  4218.  
  4219.         if(DOSBase)
  4220.         {
  4221.             CloseLibrary(DOSBase);
  4222.  
  4223.             DOSBase = NULL;
  4224.         }
  4225.  
  4226.         Forbid();
  4227.  
  4228.         ReplyMsg((struct Message *)WBenchMsg);
  4229.  
  4230.         WBenchMsg = NULL;
  4231.     }
  4232.     else
  4233.     {
  4234.         if(CloseDOS && DOSBase)
  4235.         {
  4236.             CloseLibrary(DOSBase);
  4237.  
  4238.             DOSBase = NULL;
  4239.         }
  4240.     }
  4241. }
  4242.  
  4243.     /* AddExtraAssignment(STRPTR LocalDir,STRPTR Assign):
  4244.      *
  4245.      *    Add assignments for local directories.
  4246.      */
  4247.  
  4248. STATIC VOID __regargs
  4249. AddExtraAssignment(STRPTR LocalDir,STRPTR Assign)
  4250. {
  4251.     UBYTE    LocalBuffer[40];
  4252.     BPTR    FileLock;
  4253.  
  4254.         // Add the colon, we'll need it later
  4255.  
  4256.     SPrintf(LocalBuffer,"%s:",Assign);
  4257.  
  4258.         // Is the local directory present?
  4259.  
  4260.     if(FileLock = Lock(LocalDir,ACCESS_READ))
  4261.     {
  4262.             // Is the assignment present?
  4263.  
  4264.         if(IsAssign(LocalBuffer))
  4265.         {
  4266.                 // Check to see if the local directory
  4267.                 // is already on the assignment list
  4268.  
  4269.             if(LockInAssign(FileLock,LocalBuffer))
  4270.             {
  4271.                 UnLock(FileLock);
  4272.  
  4273.                 FileLock = NULL;
  4274.             }
  4275.         }
  4276.     }
  4277.  
  4278.         // Can we attach the lock to the assignment list?
  4279.  
  4280.     if(FileLock)
  4281.     {
  4282.         Forbid();
  4283.  
  4284.             // If the assignment is already present, add the
  4285.             // new directory, else create a new assignment.
  4286.  
  4287.         if(IsAssign(LocalBuffer))
  4288.             AssignAdd(Assign,FileLock);
  4289.         else
  4290.             AssignLock(Assign,FileLock);
  4291.  
  4292.         Permit();
  4293.     }
  4294. }
  4295.  
  4296.     /* OpenAll():
  4297.      *
  4298.      *    Open all required resources or return an error message
  4299.      *    if anything went wrong.
  4300.      */
  4301.  
  4302. STRPTR __regargs
  4303. OpenAll(STRPTR ConfigPath)
  4304. {
  4305.     extern    ULONG HookEntry(struct Hook *,APTR,APTR);
  4306.  
  4307.     UBYTE         PathBuffer[MAX_FILENAME_LENGTH];
  4308.     STRPTR         Result,Error,ConfigFileName = NULL;
  4309.     WORD         i;
  4310.     struct Node    *Node;
  4311.     LONG         ErrorCode;
  4312.  
  4313.         /* Pretty cheap ;-) */
  4314.  
  4315.     Kick30 = (SysBase -> LibNode . lib_Version >= 39);
  4316.  
  4317.     if(!MemorySetup())
  4318.         return("Cannot create memory pool");
  4319.  
  4320. #ifdef DEBUG
  4321.     DebugInit();
  4322. #endif    /* DEBUG */
  4323.  
  4324.         /* Don't let it hit the ground! */
  4325.  
  4326.     ConTransfer = ConProcess;
  4327.  
  4328.         /* Remember the start of this session. */
  4329.  
  4330.     DateStamp(&SessionStart);
  4331.  
  4332.         /* Reset some flags. */
  4333.  
  4334.     BinaryTransfer    = TRUE;
  4335.  
  4336.     Status        = STATUS_READY;
  4337.  
  4338.     WasOnline    = FALSE;
  4339.     Online        = FALSE;
  4340.  
  4341.     InSequence    = FALSE;
  4342.     Quiet        = FALSE;
  4343.  
  4344.     TagDPI[0] . ti_Tag = TAG_DONE;
  4345.  
  4346.         /* Double buffered file locking. */
  4347.  
  4348.     NewList(&DoubleBufferList);
  4349.  
  4350.     InitSemaphore(&DoubleBufferSemaphore);
  4351.  
  4352.         /* ARexx command queue. */
  4353.  
  4354.     InitSemaphore(&ARexxQueueSemaphore);
  4355.  
  4356.     NewList(&ARexxQueue);
  4357.  
  4358.         /* Terminal emulation data. */
  4359.  
  4360.     InitSemaphore(&TerminalSemaphore);
  4361.  
  4362.         /* Phone number patterns and rates. */
  4363.  
  4364.     InitSemaphore(&PatternSemaphore);
  4365.  
  4366.         /* Online status. */
  4367.  
  4368.     InitSemaphore(&OnlineSemaphore);
  4369.  
  4370.         /* Text buffer task access semaphore. */
  4371.  
  4372.     InitSemaphore(&BufferTaskSemaphore);
  4373.  
  4374.         /* Set up all the lists. */
  4375.  
  4376.     NewList(&PacketHistoryList);
  4377.     NewList(&EmptyList);
  4378.     NewList(&FastMacroList);
  4379.     NewList(&TransferInfoList);
  4380.  
  4381.     NewList((struct List *)&ReviewBufferHistory);
  4382.     NewList((struct List *)&TextBufferHistory);
  4383.  
  4384.         /* Rendezvous setup. */
  4385.  
  4386.     InitSemaphore(&RendezvousSemaphore);
  4387.  
  4388.     RendezvousSemaphore . rs_Login        = RendezvousLogin;
  4389.     RendezvousSemaphore . rs_Logoff        = RendezvousLogoff;
  4390.     RendezvousSemaphore . rs_NewNode    = RendezvousNewNode;
  4391.  
  4392.         /* Open the translation tables. */
  4393.  
  4394.     LocaleOpen("term.catalog","english",20);
  4395.  
  4396.         /* Fill in the menu configuration. */
  4397.  
  4398.     LocalizeMenuTable(TermMenu,MenuLabels);
  4399.  
  4400.         /* Open intuition.library, any version. */
  4401.  
  4402.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  4403.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_INTUITION_LIBRARY_TXT));
  4404.  
  4405.     Forbid();
  4406.  
  4407.         /* Query the current public screen modes. */
  4408.  
  4409.     PublicModes = SetPubScreenModes(NULL);
  4410.  
  4411.         /* Set them back. */
  4412.  
  4413.     SetPubScreenModes(PublicModes);
  4414.  
  4415.     Permit();
  4416.  
  4417.         /* Check if we should use the old style sliders. */
  4418.  
  4419.     if(GetVar("termoldsliders",PathBuffer,256,NULL) >= 0)
  4420.         SliderType = SLIDER_KIND;
  4421.     else
  4422.         SliderType = LEVEL_KIND;
  4423.  
  4424.         /* Open some more libraries. */
  4425.  
  4426.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  4427.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GRAPHICS_LIBRARY_TXT));
  4428.  
  4429.     if(!(LayersBase = OpenLibrary("layers.library",0)))
  4430.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_LAYERS_LIBRARY_TXT));
  4431.  
  4432.         /* Install the correct routines to query
  4433.          * the rendering colours and drawing mode.
  4434.          */
  4435.  
  4436.     if(!Kick30)
  4437.     {
  4438.         ReadAPen = OldGetAPen;
  4439.         ReadBPen = OldGetBPen;
  4440.         ReadDrMd = OldGetDrMd;
  4441.         SetMask = OldSetWrMsk;
  4442.     }
  4443.     else
  4444.     {
  4445.         ReadAPen = NewGetAPen;
  4446.         ReadBPen = NewGetBPen;
  4447.         ReadDrMd = NewGetDrMd;
  4448.         SetMask = NewSetWrMsk;
  4449.     }
  4450.  
  4451.         /* Check if locale.library has already installed the operating system
  4452.          * patches required for localization.
  4453.          */
  4454.  
  4455.     LanguageCheck();
  4456.  
  4457.         /* Open the remaining libraries. */
  4458.  
  4459.     if(!(GadToolsBase = OpenLibrary("gadtools.library",0)))
  4460.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GADTOOLS_LIBRARY_TXT));
  4461.  
  4462.     if(!(AslBase = OpenLibrary("asl.library",0)))
  4463.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_ASL_LIBRARY_TXT));
  4464.  
  4465.     if(!(IFFParseBase = OpenLibrary("iffparse.library",0)))
  4466.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_IFFPARSE_LIBRARY_TXT));
  4467.  
  4468.     if(!(CxBase = OpenLibrary("commodities.library",0)))
  4469.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_COMMODITIES_LIBRARY_TXT));
  4470.  
  4471.     if(!(DiskfontBase = (struct Library *)OpenLibrary("diskfont.library",0)))
  4472.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_DISKFONT_LIBRARY_TXT));
  4473.  
  4474.         /* User interface. */
  4475.  
  4476.     if(!(GTLayoutBase = SafeOpenLibrary("PROGDIR:gtlayout.library",9)))
  4477.     {
  4478.         if(!(GTLayoutBase = SafeOpenLibrary("gtlayout.library",9)))
  4479.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GTLAYOUT_LIBRARY_TXT));
  4480.     }
  4481.  
  4482.         /* Open OwnDevUnit.library, don't complain if it fails. */
  4483.  
  4484.     OwnDevUnitBase = OpenLibrary(ODU_NAME,0);
  4485.  
  4486.         /* Open workbench.library, don't complain if it fails. */
  4487.  
  4488.     WorkbenchBase = OpenLibrary("workbench.library",0);
  4489.  
  4490.         /* Open icon.library as well, don't complain if it fails either. */
  4491.  
  4492.     IconBase = OpenLibrary("icon.library",0);
  4493.  
  4494.         /* Try to open datatypes.library, just for the fun of it. */
  4495.  
  4496.     DataTypesBase = OpenLibrary("datatypes.library",39);
  4497.  
  4498.     if(!(ConsoleRequest = (struct IOStdReq *)AllocVecPooled(sizeof(struct IOStdReq),MEMF_ANY|MEMF_CLEAR)))
  4499.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_CONSOLE_REQUEST_TXT));
  4500.  
  4501.     if(OpenDevice("console.device",CONU_LIBRARY,ConsoleRequest,0))
  4502.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_CONSOLE_DEVICE_TXT));
  4503.  
  4504.     ConsoleDevice = &ConsoleRequest -> io_Device -> dd_Library;
  4505.  
  4506.     if(!(FakeInputEvent = (struct InputEvent *)AllocVecPooled(sizeof(struct InputEvent),MEMF_ANY|MEMF_CLEAR)))
  4507.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_INPUTEVENT_TXT));
  4508.  
  4509.     FakeInputEvent -> ie_Class = IECLASS_RAWKEY;
  4510.  
  4511.     if(!(MacroKeys = (struct MacroKeys *)AllocVecPooled(sizeof(struct MacroKeys),MEMF_ANY|MEMF_CLEAR)))
  4512.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACROKEYS_TXT));
  4513.  
  4514.     if(!(CursorKeys = (struct CursorKeys *)AllocVecPooled(sizeof(struct CursorKeys),MEMF_ANY|MEMF_CLEAR)))
  4515.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_CURSORKEYS_TXT));
  4516.  
  4517.     ResetCursorKeys(CursorKeys);
  4518.  
  4519.         /* Add extra assignments. */
  4520.  
  4521.     AddExtraAssignment("PROGDIR:Fonts","Fonts");
  4522.     AddExtraAssignment("Fonts","Fonts");
  4523.     AddExtraAssignment("PROGDIR:Libs","Libs");
  4524.     AddExtraAssignment("Libs","Libs");
  4525.  
  4526.         /* Set up the attention buffers. */
  4527.  
  4528.     if(!(AttentionBuffers[0] = (STRPTR)AllocVecPooled(SCAN_COUNT * 260,MEMF_ANY|MEMF_CLEAR)))
  4529.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SEQUENCE_ATTENTION_INFO_TXT));
  4530.  
  4531.     for(i = 1 ; i < SCAN_COUNT ; i++)
  4532.         AttentionBuffers[i] = &AttentionBuffers[i - 1][260];
  4533.  
  4534.         /* Obtain the default environment storage
  4535.          * path.
  4536.          */
  4537.  
  4538.     if(!ConfigPath)
  4539.     {
  4540.         ConfigPath = PathBuffer;
  4541.  
  4542.         if(!GetEnvDOS("TERMCONFIGPATH",PathBuffer))
  4543.         {
  4544.             if(!GetEnvDOS("TERMPATH",PathBuffer))
  4545.             {
  4546.                 APTR LastPtr = ThisProcess -> pr_WindowPtr;
  4547.                 BPTR FileLock;
  4548.  
  4549.                 strcpy(PathBuffer,"TERM:config");
  4550.  
  4551.                 ThisProcess -> pr_WindowPtr = (APTR)-1;
  4552.  
  4553.                 if(FileLock = Lock("TERM:",ACCESS_READ))
  4554.                     UnLock(FileLock);
  4555.                 else
  4556.                 {
  4557.                     FileLock = DupLock(ThisProcess-> pr_HomeDir);
  4558.  
  4559.                         /* Create TERM: assignment referring to
  4560.                          * the directory `term' was loaded from.
  4561.                          */
  4562.  
  4563.                     if(!AssignLock("TERM",FileLock))
  4564.                         UnLock(FileLock);
  4565.                 }
  4566.  
  4567.                 if(!(FileLock = Lock(PathBuffer,ACCESS_READ)))
  4568.                     FileLock = CreateDir(PathBuffer);
  4569.  
  4570.                 if(FileLock)
  4571.                     UnLock(FileLock);
  4572.  
  4573.                 ThisProcess -> pr_WindowPtr = LastPtr;
  4574.             }
  4575.         }
  4576.     }
  4577.     else
  4578.     {
  4579.         if(GetFileSize(ConfigPath))
  4580.         {
  4581.             STRPTR Index;
  4582.  
  4583.             strcpy(PathBuffer,ConfigPath);
  4584.  
  4585.             Index = PathPart(PathBuffer);
  4586.  
  4587.             *Index = 0;
  4588.  
  4589.             ConfigFileName = ConfigPath;
  4590.  
  4591.             ConfigPath = PathBuffer;
  4592.         }
  4593.     }
  4594.  
  4595.         /* Check for proper assignment path if necessary. */
  4596.  
  4597.         if(!Strnicmp(ConfigPath,"TERM:",5))
  4598.         {
  4599.             APTR OldPtr = ThisProcess -> pr_WindowPtr;
  4600.             BPTR DirLock;
  4601.  
  4602.             /* Block dos requesters. */
  4603.  
  4604.             ThisProcess -> pr_WindowPtr = (APTR)-1;
  4605.  
  4606.             /* Try to get a lock on `TERM:' assignment. */
  4607.  
  4608.         if(DirLock = Lock("TERM:",ACCESS_READ))
  4609.             UnLock(DirLock);
  4610.         else
  4611.         {
  4612.                 /* Clone current directory lock. */
  4613.  
  4614.             DirLock = DupLock(ThisProcess-> pr_CurrentDir);
  4615.  
  4616.                 /* Create TERM: assignment referring to
  4617.                  * current directory.
  4618.                  */
  4619.  
  4620.             if(!AssignLock("TERM",DirLock))
  4621.                 UnLock(DirLock);
  4622.         }
  4623.  
  4624.         ThisProcess -> pr_WindowPtr = OldPtr;
  4625.         }
  4626.  
  4627.         /* Create proper path names. */
  4628.  
  4629.     if(ConfigFileName)
  4630.     {
  4631.         if(!GetFileSize(ConfigFileName))
  4632.             ConfigFileName = NULL;
  4633.     }
  4634.  
  4635.     if(!ConfigFileName)
  4636.     {
  4637.         strcpy(LastConfig,ConfigPath);
  4638.  
  4639.         AddPart(LastConfig,"term_preferences.iff",MAX_FILENAME_LENGTH);
  4640.  
  4641.         if(!GetFileSize(LastConfig))
  4642.         {
  4643.             strcpy(LastConfig,ConfigPath);
  4644.  
  4645.             AddPart(LastConfig,"term.prefs",MAX_FILENAME_LENGTH);
  4646.         }
  4647.     }
  4648.     else
  4649.         strcpy(LastConfig,ConfigFileName);
  4650.  
  4651.     strcpy(DefaultPubScreenName,"Workbench");
  4652.  
  4653.         /* Create both configuration buffers. */
  4654.  
  4655.     if(!(Config = CreateConfiguration(TRUE)))
  4656.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_PRIMARY_CONFIG_TXT));
  4657.  
  4658.     if(!(PrivateConfig = CreateConfiguration(TRUE)))
  4659.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_SECONDARY_CONFIG_TXT));
  4660.  
  4661.     ResetConfig(Config,ConfigPath);
  4662.  
  4663.         /* Read some more environment variables. */
  4664.  
  4665.     if(!WindowName[0])
  4666.     {
  4667.         if(!GetEnvDOS("TERMWINDOW",WindowName))
  4668.             strcpy(WindowName,"CON:0/11//100/term Output Window/CLOSE/SCREEN %s");
  4669.     }
  4670.  
  4671.     GetEnvDOS("EDITOR",Config -> PathConfig -> Editor);
  4672.  
  4673.         /* Look for the default configuration file. */
  4674.  
  4675.     if(!ReadConfig(LastConfig,Config))
  4676.     {
  4677.         ResetConfig(Config,ConfigPath);
  4678.  
  4679.         Initializing = TRUE;
  4680.  
  4681.         LoadColours = TRUE;
  4682.  
  4683.             // Now we can safely assume that this is the
  4684.             // first invocation of this program on the
  4685.             // current setup
  4686.  
  4687.         FirstInvocation = TRUE;
  4688.     }
  4689.     else
  4690.     {
  4691.         Current2DefaultPalette(Config);
  4692.  
  4693.         if(Config -> ScreenConfig -> ColourMode == COLOUR_AMIGA)
  4694.             Initializing = FALSE;
  4695.         else
  4696.             Initializing = TRUE;
  4697.     }
  4698.  
  4699.     if(UseNewDevice)
  4700.         strcpy(Config -> SerialConfig -> SerialDevice,NewDevice);
  4701.  
  4702.     if(UseNewUnit)
  4703.         Config -> SerialConfig -> UnitNumber = NewUnit;
  4704.  
  4705.     if(Config -> MiscConfig -> OpenFastMacroPanel)
  4706.         HadFastMacros = TRUE;
  4707.  
  4708.     strcpy(LastPhone,    Config -> PathConfig -> DefaultStorage);
  4709.     AddPart(LastPhone,    "term_phonebook.iff",MAX_FILENAME_LENGTH);
  4710.  
  4711.     if(!GetFileSize(LastPhone))
  4712.     {
  4713.         strcpy(LastPhone,    Config -> PathConfig -> DefaultStorage);
  4714.         AddPart(LastPhone,    "phonebook.prefs",MAX_FILENAME_LENGTH);
  4715.     }
  4716.  
  4717.     strcpy(LastKeys,    Config -> PathConfig -> DefaultStorage);
  4718.     AddPart(LastKeys,    "term_hotkeys.iff",MAX_FILENAME_LENGTH);
  4719.  
  4720.     if(!GetFileSize(LastKeys))
  4721.     {
  4722.         strcpy(LastKeys,    Config -> PathConfig -> DefaultStorage);
  4723.         AddPart(LastKeys,    "hotkeys.prefs",MAX_FILENAME_LENGTH);
  4724.     }
  4725.  
  4726.     strcpy(LastSpeech,    Config -> PathConfig -> DefaultStorage);
  4727.     AddPart(LastSpeech,    "term_speech.iff",MAX_FILENAME_LENGTH);
  4728.  
  4729.     if(!GetFileSize(LastSpeech))
  4730.     {
  4731.         strcpy(LastSpeech,    Config -> PathConfig -> DefaultStorage);
  4732.         AddPart(LastSpeech,    "speech.prefs",MAX_FILENAME_LENGTH);
  4733.     }
  4734.  
  4735.     strcpy(LastFastMacros,    Config -> PathConfig -> DefaultStorage);
  4736.     AddPart(LastFastMacros,    "term_fastmacros.iff",MAX_FILENAME_LENGTH);
  4737.  
  4738.     if(!GetFileSize(LastFastMacros))
  4739.     {
  4740.         strcpy(LastFastMacros,    Config -> PathConfig -> DefaultStorage);
  4741.         AddPart(LastFastMacros,    "fastmacros.prefs",MAX_FILENAME_LENGTH);
  4742.     }
  4743.  
  4744.     if(Config -> FileConfig -> MacroFileName[0])
  4745.         strcpy(LastMacros,Config -> FileConfig -> MacroFileName);
  4746.     else
  4747.     {
  4748.         strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4749.         AddPart(LastMacros,    "term_macros.iff",MAX_FILENAME_LENGTH);
  4750.  
  4751.         if(!GetFileSize(LastMacros))
  4752.         {
  4753.             strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4754.             AddPart(LastMacros,    "macros.prefs",MAX_FILENAME_LENGTH);
  4755.  
  4756.             if(!GetFileSize(LastMacros))
  4757.             {
  4758.                 strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4759.                 AddPart(LastMacros,    "functionkeys.prefs",MAX_FILENAME_LENGTH);
  4760.             }
  4761.         }
  4762.     }
  4763.  
  4764.         /* Load the keyboard macros. */
  4765.  
  4766.     if(!LoadMacros(LastMacros,MacroKeys))
  4767.         ResetMacroKeys(MacroKeys);
  4768.  
  4769.     if(Config -> FileConfig -> CursorFileName[0])
  4770.         strcpy(LastCursorKeys,Config -> FileConfig -> CursorFileName);
  4771.     else
  4772.     {
  4773.         strcpy(LastCursorKeys,    Config -> PathConfig -> DefaultStorage);
  4774.         AddPart(LastCursorKeys,    "cursorkeys.prefs",MAX_FILENAME_LENGTH);
  4775.     }
  4776.  
  4777.         /* Load the cursor keys. */
  4778.  
  4779.     if(!ReadIFFData(LastCursorKeys,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  4780.         ResetCursorKeys(CursorKeys);
  4781.  
  4782.     strcpy(LastSound,    Config -> PathConfig -> DefaultStorage);
  4783.     AddPart(LastSound,    "sound.prefs",MAX_FILENAME_LENGTH);
  4784.  
  4785.         /* Load the sound settings. */
  4786.  
  4787.     memset(&SoundConfig,0,sizeof(struct SoundConfig));
  4788.  
  4789.     SoundConfig . Volume = 100;
  4790.  
  4791.     if(!ReadIFFData(LastSound,&SoundConfig,sizeof(struct SoundConfig),ID_SOUN))
  4792.         strcpy(SoundConfig . BellFile,Config -> TerminalConfig -> BeepFileName);
  4793.  
  4794.         /* Initialize the sound support routines. */
  4795.  
  4796.     SoundInit();
  4797.  
  4798.         /* Load the phone number pattern / rates settings. */
  4799.  
  4800.     strcpy(LastPattern,    Config -> PathConfig -> DefaultStorage);
  4801.     AddPart(LastPattern,    "rates.prefs",MAX_FILENAME_LENGTH);
  4802.  
  4803.     if(!(PatternList = LoadTimeDateList(LastPattern,&ErrorCode)))
  4804.     {
  4805.         if(!(PatternList = (struct List *)AllocVecPooled(sizeof(struct List),MEMF_ANY)))
  4806.             return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4807.         else
  4808.             NewList(PatternList);
  4809.     }
  4810.  
  4811.         /* Are we to load the translation tables? */
  4812.  
  4813.     strcpy(LastTranslation,Config -> FileConfig -> TranslationFileName);
  4814.  
  4815.     if(Config -> FileConfig -> TranslationFileName[0])
  4816.     {
  4817.         if(SendTable = AllocTranslationTable())
  4818.         {
  4819.             if(ReceiveTable = AllocTranslationTable())
  4820.             {
  4821.                 if(!LoadTranslationTables(Config -> FileConfig -> TranslationFileName,SendTable,ReceiveTable))
  4822.                 {
  4823.                     FreeTranslationTable(SendTable);
  4824.  
  4825.                     SendTable = NULL;
  4826.  
  4827.                     FreeTranslationTable(ReceiveTable);
  4828.  
  4829.                     ReceiveTable = NULL;
  4830.                 }
  4831.                 else
  4832.                 {
  4833.                     if(IsStandardTable(SendTable) && IsStandardTable(ReceiveTable))
  4834.                     {
  4835.                         FreeTranslationTable(SendTable);
  4836.  
  4837.                         SendTable = NULL;
  4838.  
  4839.                         FreeTranslationTable(ReceiveTable);
  4840.  
  4841.                         ReceiveTable = NULL;
  4842.                     }
  4843.                 }
  4844.             }
  4845.             else
  4846.             {
  4847.                 FreeTranslationTable(SendTable);
  4848.  
  4849.                 SendTable = NULL;
  4850.             }
  4851.         }
  4852.     }
  4853.  
  4854.     SendSetup();
  4855.  
  4856.         /* Set up the capture parser. */
  4857.  
  4858.     if(!CaptureParserInit())
  4859.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4860.  
  4861.     ConOutputUpdate();
  4862.  
  4863.         /* Load the fast! macro settings. */
  4864.  
  4865.     LoadFastMacros(LastFastMacros,&FastMacroList);
  4866.  
  4867.         /* Load the speech settings. */
  4868.  
  4869.     if(!ReadIFFData(LastSpeech,&SpeechConfig,sizeof(struct SpeechConfig),ID_SPEK))
  4870.     {
  4871.         SpeechConfig . Rate        = DEFRATE;
  4872.         SpeechConfig . Pitch        = DEFPITCH;
  4873.         SpeechConfig . Frequency    = DEFFREQ;
  4874.         SpeechConfig . Volume        = DEFVOL;
  4875.         SpeechConfig . Sex        = DEFSEX;
  4876.         SpeechConfig . Enabled        = FALSE;
  4877.     }
  4878.  
  4879.         /* Load the hotkey settings. */
  4880.  
  4881.     if(!LoadHotkeys(LastKeys,&Hotkeys))
  4882.     {
  4883.         strcpy(Hotkeys . termScreenToFront,    "lshift rshift return");
  4884.         strcpy(Hotkeys . BufferScreenToFront,    "control rshift return");
  4885.         strcpy(Hotkeys . SkipDialEntry,        "control lshift rshift return");
  4886.         strcpy(Hotkeys . AbortARexx,        "lshift rshift escape");
  4887.  
  4888.         Hotkeys . CommodityPriority    = 0;
  4889.         Hotkeys . HotkeysEnabled    = TRUE;
  4890.     }
  4891.  
  4892.         /* Initialize the data flow parser. */
  4893.  
  4894.     FlowInit(TRUE);
  4895.  
  4896.         /* Set up the edit list labels for the phonebook. */
  4897.  
  4898.     if(!(EditList = (struct List *)AllocVecPooled(sizeof(struct List),MEMF_ANY)))
  4899.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4900.  
  4901.     NewList(EditList);
  4902.  
  4903.     if(!(EditLabels = (STRPTR *)AllocVecPooled(sizeof(STRPTR) * (MSG_PHONEPANEL_RATES_TXT - MSG_PHONEPANEL_SERIAL_TXT + 1),MEMF_ANY | MEMF_CLEAR)))
  4904.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4905.  
  4906.     for(i = MSG_PHONEPANEL_SERIAL_TXT ; i <= MSG_PHONEPANEL_RATES_TXT ; i++)
  4907.     {
  4908.         if(Node = (struct Node *)AllocVecPooled(sizeof(struct Node) + strlen(LocaleString(i)) + 2,MEMF_ANY))
  4909.         {
  4910.             EditLabels[i - MSG_PHONEPANEL_SERIAL_TXT] = Node -> ln_Name = (STRPTR)(Node + 1);
  4911.  
  4912.             Node -> ln_Name[0] = ' ';
  4913.  
  4914.             strcpy(&Node -> ln_Name[1],LocaleString(i));
  4915.  
  4916.             AddTail(EditList,Node);
  4917.         }
  4918.         else
  4919.             return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4920.     }
  4921.  
  4922.         /* Set up parsing jump tables. */
  4923.  
  4924.     if(!(SpecialTable = (JUMP *)AllocVecPooled(256 * sizeof(JUMP),MEMF_CLEAR | MEMF_ANY)))
  4925.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4926.  
  4927.     for(i = 0 ; i < sizeof(SpecialKeys) / sizeof(struct SpecialKey) ; i++)
  4928.         SpecialTable[SpecialKeys[i] . Key] = (JUMP)SpecialKeys[i] . Routine;
  4929.  
  4930.     if(!(AbortTable = (JUMP *)AllocVecPooled(256 * sizeof(JUMP),MEMF_ANY)))
  4931.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4932.  
  4933.     for(i = 0 ; i < 256 ; i++)
  4934.     {
  4935.         switch(AbortMap[i])
  4936.         {
  4937.             case 0:    AbortTable[i] = (JUMP)ParseCode;
  4938.                 break;
  4939.  
  4940.             case 1:    AbortTable[i] = (JUMP)DoCancel;
  4941.                 break;
  4942.  
  4943.             case 2:    AbortTable[i] = (JUMP)DoNewEsc;
  4944.                 break;
  4945.  
  4946.             case 3:    AbortTable[i] = (JUMP)DoNewCsi;
  4947.                 break;
  4948.         }
  4949.     }
  4950.  
  4951.         /* Create all generic lists. */
  4952.  
  4953.     for(i = GLIST_UPLOAD ; i < GLIST_COUNT ; i++)
  4954.     {
  4955.         if(!(GenericListTable[i] = CreateGenericList()))
  4956.             return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4957.     }
  4958.  
  4959.         /* Load the trap settings. */
  4960.  
  4961.     strcpy(LastTraps,    Config -> PathConfig -> DefaultStorage);
  4962.     AddPart(LastTraps,    "trap.prefs",MAX_FILENAME_LENGTH);
  4963.  
  4964.     WatchTraps = TRUE;
  4965.  
  4966.     LoadTraps(LastTraps,GenericListTable[GLIST_TRAP]);
  4967.  
  4968.         /* Create the special event queue. */
  4969.  
  4970.     if(!(SpecialQueue = CreateMsgQueue(NULL,0)))
  4971.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4972.  
  4973.         /* Set up the serial driver. */
  4974.  
  4975.     if(Error = CreateSerial())
  4976.     {
  4977.         MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error);
  4978.  
  4979.         DeleteSerial();
  4980.     }
  4981.     else
  4982.     {
  4983.         if(SerialMessage)
  4984.         {
  4985.             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  4986.  
  4987.             SerialMessage = NULL;
  4988.         }
  4989.     }
  4990.  
  4991.         /* Get a signal bit. */
  4992.  
  4993.     if((CheckBit = AllocSignal(-1)) == -1)
  4994.         return(LocaleString(MSG_TERMINIT_FAILED_TO_GET_CHECK_SIGNAL_TXT));
  4995.  
  4996.     if(!(TimePort = (struct MsgPort *)CreateMsgPort()))
  4997.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  4998.  
  4999.     if(!(TimeRequest = (struct timerequest *)CreateIORequest(TimePort,sizeof(struct timerequest))))
  5000.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_IOREQUEST_TXT));
  5001.  
  5002.     if(OpenDevice("timer.device",UNIT_VBLANK,TimeRequest,0))
  5003.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_TIMER_DEVICE_TXT));
  5004.  
  5005.     TimerBase = &TimeRequest -> tr_node . io_Device -> dd_Library;
  5006.  
  5007.         /* Add the global term port. */
  5008.  
  5009.     if(!TermPort)
  5010.     {
  5011.         if(!(TermPort = (struct TermPort *)AllocVec(sizeof(struct TermPort) + 11,MEMF_PUBLIC|MEMF_CLEAR)))
  5012.             return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_GLOBAL_PORT_TXT));
  5013.         else
  5014.         {
  5015.             NewList(&TermPort -> ExecNode . mp_MsgList);
  5016.  
  5017.             InitSemaphore(&TermPort -> OpenSemaphore);
  5018.  
  5019.             TermPort -> ExecNode . mp_Flags            = PA_IGNORE;
  5020.             TermPort -> ExecNode . mp_Node . ln_Name    = (char *)(TermPort + 1);
  5021.  
  5022.             strcpy(TermPort -> ExecNode . mp_Node . ln_Name,"term Port");
  5023.  
  5024.             AddPort(&TermPort -> ExecNode);
  5025.         }
  5026.     }
  5027.  
  5028.         /* Keep another term task from removing the port. */
  5029.  
  5030.     TermPort -> HoldIt = TRUE;
  5031.  
  5032.         /* Install a new term process. */
  5033.  
  5034.     ObtainSemaphore(&TermPort -> OpenSemaphore);
  5035.  
  5036.     TermPort -> OpenCount++;
  5037.  
  5038.     TermPort -> HoldIt = FALSE;
  5039.  
  5040.     TermID = TermPort -> ID++;
  5041.  
  5042.     ReleaseSemaphore(&TermPort -> OpenSemaphore);
  5043.  
  5044.         /* Set up the ID string. */
  5045.  
  5046.     if(TermID)
  5047.         SPrintf(TermIDString,"TERM.%ld",TermID);
  5048.     else
  5049.         strcpy(TermIDString,"TERM");
  5050.  
  5051.     if(RexxPortName[0])
  5052.     {
  5053.         WORD i;
  5054.  
  5055.         for(i = 0 ; i < strlen(RexxPortName) ; i++)
  5056.             RexxPortName[i] = ToUpper(RexxPortName[i]);
  5057.  
  5058.         if(FindPort(RexxPortName))
  5059.             RexxPortName[0] = 0;
  5060.     }
  5061.  
  5062.     if(!RexxPortName[0])
  5063.         strcpy(RexxPortName,TermIDString);
  5064.  
  5065.         /* Install the hotkey handler. */
  5066.  
  5067.     SetupCx();
  5068.  
  5069.         /* Allocate the first few lines for the display buffer. */
  5070.  
  5071.     if(!CreateBuffer())
  5072.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_VIEW_BUFFER_TXT));
  5073.  
  5074.     if(!(XprIO = (struct XPR_IO *)AllocVec(sizeof(struct XPR_IO),MEMF_ANY|MEMF_CLEAR)))
  5075.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_PROTOCOL_BUFFER_TXT));
  5076.  
  5077.         /* Set up the external emulation macro data. */
  5078.  
  5079.     if(!(XEM_MacroKeys = (struct XEmulatorMacroKey *)AllocVecPooled((2 + 10 * 4) * sizeof(struct XEmulatorMacroKey),MEMF_ANY|MEMF_CLEAR)))
  5080.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACRO_KEY_DATA_TXT));
  5081.  
  5082.     strcpy(LastXprLibrary,Config -> TransferConfig -> DefaultLibrary);
  5083.  
  5084.     ProtocolSetup(FALSE);
  5085.  
  5086.         /* Load a keymap file if required. */
  5087.  
  5088.     if(Config -> TerminalConfig -> KeyMapFileName[0])
  5089.         KeyMap = LoadKeyMap(Config -> TerminalConfig -> KeyMapFileName);
  5090.  
  5091.     if(!(TermRexxPort = (struct MsgPort *)CreateMsgPort()))
  5092.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  5093.  
  5094.         /* If rexxsyslib.library opens cleanly it's time for
  5095.          * us to create the background term Rexx server.
  5096.          */
  5097.  
  5098.     if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0))
  5099.     {
  5100.             /* Create a background process handling the
  5101.              * rexx messages asynchronously.
  5102.              */
  5103.  
  5104.         Forbid();
  5105.  
  5106.         if(RexxProcess = (struct Process *)CreateNewProcTags(
  5107.             NP_Entry,    RexxServer,
  5108.             NP_Name,    "term Rexx Process",
  5109.             NP_Priority,    5,
  5110.             NP_StackSize,    8192,
  5111.             NP_WindowPtr,    -1,
  5112.         TAG_END))
  5113.         {
  5114.             ClrSignal(SIG_HANDSHAKE);
  5115.  
  5116.             Wait(SIG_HANDSHAKE);
  5117.         }
  5118.  
  5119.         Permit();
  5120.  
  5121.         if(!RexxProcess)
  5122.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_AREXX_PROCESS_TXT));
  5123.     }
  5124.  
  5125.         /* Install the public screen name, assumes that the user
  5126.          * wants the window to be opened on the screen, rather than
  5127.          * opening a custom screen.
  5128.          */
  5129.  
  5130.     if(SomePubScreenName[0])
  5131.     {
  5132.         strcpy(Config -> ScreenConfig -> PubScreenName,SomePubScreenName);
  5133.  
  5134.         Config -> ScreenConfig -> Blinking    = FALSE;
  5135.         Config -> ScreenConfig -> FasterLayout    = FALSE;
  5136.         Config -> ScreenConfig -> UseWorkbench    = TRUE;
  5137.  
  5138.         SomePubScreenName[0] = 0;
  5139.     }
  5140.  
  5141.     CreateQueueProcess();
  5142.  
  5143.     Forbid();
  5144.  
  5145.     RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Name = RexxPortName;
  5146.     RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Pri  = -127;
  5147.  
  5148.     AddSemaphore(&RendezvousSemaphore);
  5149.  
  5150.     Permit();
  5151.  
  5152. //    DebugInit();
  5153.  
  5154.     if(DoIconify)
  5155.         return(NULL);
  5156.     else
  5157.     {
  5158.             /* Create the whole display. */
  5159.  
  5160.         if(Result = CreateDisplay(TRUE))
  5161.             return(Result);
  5162.         else
  5163.         {
  5164.             PubScreenStuff();
  5165.  
  5166.             return(NULL);
  5167.         }
  5168.     }
  5169. }
  5170.